we got the gdt working!
This commit is contained in:
parent
da7123e518
commit
c79e957f38
6 changed files with 56 additions and 19 deletions
|
@ -1,3 +1,5 @@
|
|||
#include "gdt.h"
|
||||
|
||||
void encode_gdt_entry(unsigned short int * target, struct GDT source) {
|
||||
if((source.limit > 65536) && ((source.limit & 0xFFF) != 0xFFF)) {
|
||||
/* This needs to error out. */
|
||||
|
|
|
@ -8,7 +8,7 @@ struct GDT {
|
|||
};
|
||||
|
||||
void encode_gdt_entry(unsigned short int *, struct GDT);
|
||||
extern void set_gdt(void);
|
||||
extern void set_gdt(unsigned short int[], int);
|
||||
extern void reload_segments(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,24 +6,20 @@ gdtr:
|
|||
.int 0
|
||||
|
||||
set_gdt:
|
||||
.fnstart
|
||||
.func set_gdt
|
||||
mov 4(%esp), %eax
|
||||
mov %eax, 2($gdtr)
|
||||
mov %eax, gdtr+2
|
||||
mov 8(%esp), %ax
|
||||
mov %ax, $gdtr
|
||||
lgdt $gdtr
|
||||
mov %ax, gdtr
|
||||
lgdt gdtr
|
||||
ret
|
||||
.fnend
|
||||
.endfunc
|
||||
|
||||
.globl reload_segments
|
||||
.type reload_segments,%function
|
||||
|
||||
reload_segments:
|
||||
.fnstart
|
||||
jmp 0x08:reload_CS
|
||||
.fnend
|
||||
|
||||
reload_CS:
|
||||
.func reload_segments
|
||||
mov 0x10, %ax
|
||||
mov %ax, %ds
|
||||
mov %ax, %es
|
||||
|
@ -31,4 +27,4 @@ reload_CS:
|
|||
mov %ax, %gs
|
||||
mov %ax, %ss
|
||||
ret
|
||||
|
||||
.endfunc
|
|
@ -3,6 +3,10 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/io.h>
|
||||
#include "gdt.h"
|
||||
|
||||
int tss[16][2];
|
||||
|
||||
int test_libc(void) {
|
||||
int failed = 0;
|
||||
|
@ -10,12 +14,8 @@ int test_libc(void) {
|
|||
printf("==Testing stdio.h==\n");
|
||||
|
||||
printf("printf(\"%%d\", 10): %d (expected 10)\n", 10);
|
||||
printf("printf(\"%%d\", -10): %d (expected -10)\n", -10);
|
||||
printf("printf(\"%%i\", 10): %d (expected 10)\n", 10);
|
||||
printf("printf(\"%%o\", 014): %o (expected 14)\n", 014);
|
||||
printf("printf(\"%%o\", 14): %o (expected 16)\n", 14);
|
||||
printf("printf(\"%%u\", 10): %u (expected 10)\n", 10);
|
||||
printf("printf(\"%%x\", 0xC9A): %x (expected c9a)\n", 0xC9A);
|
||||
printf("printf(\"%%x\", 26): %x (expected 1a)\n", 26);
|
||||
printf("printf(\"%%X\", 0xC9A): %x (expected C9A)\n", 0xC9A);
|
||||
printf("printf(\"%%p\", &i): %p (expected 0x[hex])\n", &failed);
|
||||
|
@ -95,12 +95,48 @@ int test_libc(void) {
|
|||
}
|
||||
|
||||
printf("Tests failed: %d\n", failed);
|
||||
printf("One final test: If you can see this, the TTY can scroll.");
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
void NMI_disable(void) {
|
||||
outb(0x70, inb(0x70) | 0x80);
|
||||
}
|
||||
|
||||
void NMI_enable(void) {
|
||||
outb(0x70, inb(0x70) & 0x7F);
|
||||
}
|
||||
|
||||
void A20_enable(void) {
|
||||
unsigned short int a = inb(0x92);
|
||||
if((a & 2) != 0) {
|
||||
return;
|
||||
}
|
||||
a |= 2;
|
||||
outb(a, 0x92);
|
||||
}
|
||||
|
||||
void setup_gdt(void) {
|
||||
struct GDT gdt[4];
|
||||
|
||||
gdt[0].base = 0; gdt[0].limit = 0; gdt[0].type = 0;
|
||||
gdt[1].base = 0; gdt[1].limit = 0xFFFFFFFF; gdt[1].type = 0x9A;
|
||||
gdt[2].base = 0; gdt[2].limit = 0xFFFFFFFF; gdt[2].type = 0x92;
|
||||
gdt[3].base = (unsigned int) tss; gdt[3].limit=sizeof(tss); gdt[3].type = 0x89;
|
||||
|
||||
unsigned short int GDT[4];
|
||||
encode_gdt_entry(&GDT[0], gdt[0]);
|
||||
encode_gdt_entry(&GDT[1], gdt[1]);
|
||||
encode_gdt_entry(&GDT[2], gdt[2]);
|
||||
encode_gdt_entry(&GDT[3], gdt[3]);
|
||||
|
||||
set_gdt(GDT, sizeof(GDT));
|
||||
}
|
||||
|
||||
int init(void) {
|
||||
NMI_disable();
|
||||
A20_enable();
|
||||
setup_gdt();
|
||||
printf("Fenix Dev Pre-release v0.0.3\n");
|
||||
return test_libc();
|
||||
}
|
||||
|
|
|
@ -3,4 +3,4 @@ KERNEL_ARCH_CPPFLAGS=
|
|||
KERNEL_ARCH_LDFLAGS=
|
||||
KERNEL_ARCH_LIBS=
|
||||
|
||||
KERNEL_ARCH_OBJS=$(ARCHDIR)/boot.o $(ARCHDIR)/tty.o $(ARCHDIR)/init.o $(ARCHDIR)/cmos.o
|
||||
KERNEL_ARCH_OBJS=$(ARCHDIR)/boot.o $(ARCHDIR)/tty.o $(ARCHDIR)/init.o $(ARCHDIR)/cmos.o $(ARCHDIR)/gdt.o $(ARCHDIR)/gdt_load.o
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
extern int tss[16][2];
|
||||
extern unsigned short int * GDT;
|
||||
|
||||
int test_libc(void);
|
||||
int init(void);
|
||||
|
||||
|
|
Loading…
Reference in a new issue