Skip to content

Commit 1a24191

Browse files
committed
File environment.asm responsible for loading the GDT with relevant descriptors.
Discarded gdt related code elsewhere (gdt.c, gdt.h, load_gdt.asm)..
1 parent c1ab14f commit 1a24191

File tree

6 files changed

+64
-208
lines changed

6 files changed

+64
-208
lines changed

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ ALL_OBJ := environment.o \
1212
kernel.o \
1313
string.o \
1414
idt.o \
15-
gdt.o \
1615
load_gdt.o
1716
ALL_DEP := $(patsubst %.o,.%.d,$(ALL_OBJ))
1817

@@ -49,8 +48,7 @@ testos.bin: $(ALL_OBJ)
4948
@$(LD) -o $@ $(LD_FLAGS) $^
5049

5150
clean:
52-
rm -f *.o
53-
rm -f testos.bin
51+
rm -f $(ALL_DEP) $(ALL_OBJ)
5452

5553
ifneq ($(MAKECMDGOALS),clean)
5654
-include $(ALL_DEP)

environment.asm

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,54 @@
1+
gdtr:
2+
gdt_limit dw 8*5
3+
gdt_base dd gd_table
4+
5+
align 8
6+
gd_table:
7+
.gdt_e_null:
8+
dq 0
9+
.gdt_e_code_0:
10+
dw 0xffff
11+
dw 0
12+
db 0
13+
db 0x9a
14+
db 11001111b
15+
db 0
16+
.gdt_e_data_0:
17+
dw 0xffff
18+
dw 0
19+
db 0
20+
db 0x92
21+
db 11001111b
22+
db 0
23+
.gdt_e_code_3:
24+
dw 0xffff
25+
dw 0
26+
db 0
27+
db 0xfa
28+
db 11001111b
29+
db 0
30+
.gdt_e_data_3:
31+
dw 0xffff
32+
dw 0
33+
db 0
34+
db 0xf2
35+
db 11001111b
36+
db 0
37+
138
global environment
239
environment:
340
mov esp, stack_top
41+
gdt_setup:
42+
lgdt [gdtr]
43+
jmp 0x08:gdt_reload
44+
gdt_reload:
45+
mov ax, 0x10
46+
mov ds, ax
47+
mov es, ax
48+
mov fs, ax
49+
mov gs, ax
50+
mov ss, ax
51+
finish:
452
extern kernel_main
553
call kernel_main
654
cli
@@ -9,6 +57,7 @@ environment:
957

1058
section .bss
1159
align 4
60+
1261
stack_bottom:
1362
resb 16384
1463
stack_top:

gdt.c

Lines changed: 0 additions & 42 deletions
This file was deleted.

gdt.h

Lines changed: 0 additions & 151 deletions
This file was deleted.

kernel.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
#include "terminal.h"
2-
#include "gdt.h"
32

43
void kernel_main()
54
{
65
terminal_clear(vga_entry(' ', vga_entry_color(VGA_COLOR_GRAY, VGA_COLOR_BLUE)));
7-
terminal_write_str("TestOS V 0.0000001\n");
8-
gdt_init();
96

10-
return;
11-
}
7+
terminal_write_str("Test\n");
128

13-
void* do_nothing(void* ptr)
14-
{
15-
return ptr + 1;
16-
}
9+
return;
10+
}

load_gdt.asm

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ gdt_base DD 0 ;base
44

55
global load_gdt
66
load_gdt:
7-
mov eax, [esp+4]
8-
mov cx, [esp+8]
7+
mov eax, [esp+4] ;load base parameter
8+
mov cx, [esp+8] ;load limit parameter
99
mov [gdt_base], eax
1010
mov [gdt_limit], cx
1111
lgdt [gdtr]
12-
ret
12+
jmp 2*8:reload
13+
reload:
14+
mov ax, 0x10
15+
mov ds, ax
16+
mov es, ax
17+
mov fs, ax
18+
mov gs, ax
19+
mov ss, ax
20+
ret

0 commit comments

Comments
 (0)