[freenos] r400 committed - Implemented support for managing the Task State Segment....

  • From: freenos@xxxxxxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Mon, 18 Oct 2010 23:51:40 +0000

Revision: 400
Author: nieklinnenbank
Date: Mon Oct 18 16:43:03 2010
Log: Implemented support for managing the Task State Segment.
A valid TSS is required on x86 for each CPU, as it contains
a pointer to the ring0 stack. When an interrupt or system
call occurs and the system changes privilege level, the
CPU fetches it's stack pointer from the TSS, and thus
we need one for each CPU.

http://code.google.com/p/freenos/source/detail?r=400

Added:
 /branches/scratch/include/x86/tss.h
 /branches/scratch/system/x86/pc/tss.c

=======================================
--- /dev/null
+++ /branches/scratch/include/x86/tss.h Mon Oct 18 16:43:03 2010
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2010 Niek Linnenbank
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __TSS_H
+#define __TSS_H
+
+#include "types.h"
+#include "macro.h"
+
+typedef struct tss
+{
+    u16 prev_link, prev_link_high;
+    u32 esp0;
+    u16 ss0, ss0_high;
+    u32 esp1;
+    u16 ss1, ss1_high;
+    u32 esp2;
+    u16 ss2, ss2_high;
+    u32 cr3;
+    u32 eip;
+    u32 eflags;
+    u32 eax, ecx, edx, ebx;
+    u32 esp;
+    u32 ebp;
+    u32 esi, edi;
+    u16 es, es_high;
+    u16 cs, cs_high;
+    u16 ss, ss_high;
+    u16 ds, ds_high;
+    u16 fs, fs_high;
+    u16 gs, gs_high;
+    u16 ldt, ldt_high;
+    u16 reserved;
+    u16 io_map_base;
+}
+PACKED tss_t;
+
+extern void tss_init(void);
+extern tss_t * tss_get(void);
+extern void tss_update(addr_t kern_stack, uint kern_seg);
+
+#endif /* __TSS_H */
=======================================
--- /dev/null
+++ /branches/scratch/system/x86/pc/tss.c       Mon Oct 18 16:43:03 2010
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2010 Niek Linnenbank
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <FreeNOS/tss.h>
+#include <FreeNOS/gdt.h>
+#include <FreeNOS/smp.h>
+#include <FreeNOS/cpu.h>
+#include <FreeNOS/virt_memory.h>
+#include <string.h>
+
+static tss_t ALIGN(PAGE_SIZE) tss[SMP_MAX];
+
+void tss_init(void)
+{
+    memset(&tss[smp_id()], 0, sizeof(tss_t));
+    ltr(KERN_TSS_SEL);
+}
+
+tss_t * tss_get(void)
+{
+    return &tss[smp_id()];
+}
+
+void tss_update(addr_t kern_stack, uint kern_seg)
+{
+    tss[smp_id()].esp0 = kern_stack;
+    tss[smp_id()].ss0  = kern_seg;
+}

Other related posts:

  • » [freenos] r400 committed - Implemented support for managing the Task State Segment.... - freenos