Skip to content

Commit 69c0b12

Browse files
committed
Define and use segment selector constants
1 parent ee67ae1 commit 69c0b12

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/arch/i686/gdt.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
#include <stdint.h>
55

6+
#define KERNEL_DATA_SEG 0x10
7+
#define USER_CODE_SEG 0x1B
8+
#define USER_DATA_SEG 0x23
9+
#define TSS_SEGMENT_SELECTOR (5 << 3)
10+
611
struct tss_entry {
712
uint32_t prev_tss; // The previous TSS - with hardware task switching this is used
813
uint32_t esp0; // The stack pointer to load when we change to kernel mode

src/arch/i686/user.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ void user_init(void) {
191191
uint32_t esp0 = 0;
192192
asm volatile ("mov %%esp, %0" : "=r" (esp0));
193193
tss.esp0 = esp0;
194-
tss.ss0 = 0x10;
195-
tss.cs = 0x1B;
196-
tss.ds = 0x23;
197-
tss.es = 0x23;
198-
tss.fs = 0x23;
199-
tss.gs = 0x23;
200-
tss.ss = 0x23;
194+
tss.ss0 = KERNEL_DATA_SEG;
195+
tss.cs = USER_CODE_SEG;
196+
tss.ds = USER_DATA_SEG;
197+
tss.es = USER_DATA_SEG;
198+
tss.fs = USER_DATA_SEG;
199+
tss.gs = USER_DATA_SEG;
200+
tss.ss = USER_DATA_SEG;
201201
asm volatile("ltr %%ax" : : "a"(5 << 3));
202202

203203
jmp_ring3(p1.sp, p1.ip);

0 commit comments

Comments
 (0)