3 #include <video_defines.h>
6 #include <pci-bother.h>
9 #include "../net/net.h"
10 #include "vga-overlay.h"
12 extern void smi_init();
15 void set_cr0(unsigned int);
16 void ps_switch_stack (void (*call)(), int stack);
18 extern int entry_initialized;
19 extern int _bss, _bssend, _end;
23 register unsigned int _temp__; \
24 asm volatile("mov %%cr0, %0" : "=r" (_temp__)); \
29 #define set_cr3(value) \
31 register unsigned int _temp__ = (value); \
32 asm volatile("mov %0, %%cr3" : : "r" (_temp__)); \
34 #define CR0_PG 0x80000000
36 #define MAP_FLAGS (PTE_PRESENT | PTE_READ_WRITE)
38 void * pt_setup(int smbase, int tseg_start, int tseg_size) {
42 /* The page directory and page table live at SMBASE and SMBASE + 0x1000,
43 * respectively; clear them. */
44 int * pagedirectory = (int *) tseg_start;
45 int * pagetable = (int *) (tseg_start + 0x1000);
47 /* Clear out the page directory except for one entry pointing to the
48 * page table, and clear the page table entirely. */
50 pagedirectory[0] = (tseg_start + 0x1000) | PTE_PRESENT | PTE_READ_WRITE;
52 for (i = 1; i < 1024; i++)
58 for (i = 0; i < 1024; i++)
64 /* The page at 0x10000 - 0x10FFF points to the SMI entry point,
66 pagetable[16] = (0x8000 + smbase) | MAP_FLAGS;
68 /* 0x11000 to 0x1EFFF map to the rest of ASEG up to SMBASE + 0xF000;
69 * the page containing the saved state is not mappped to our code
72 for (i = 0; i < 8; i++)
74 pagetable[17 + i] = (i * 0x1000 + smbase) | MAP_FLAGS;
77 for (i = 0; i < 6; i++)
79 pagetable[25 + i] = (smbase + 0x9000 + i * 0x1000) | MAP_FLAGS;
83 /* Map 0xA8000 to itself. */
85 for (i = 0; i < 32; i++) {
86 pagetable[0xA0 + i] = (0xA0000 + i * 0x1000) | MAP_FLAGS;
89 /* Map 0x200000 to TSEG */
90 for (i = 0; i < 128; i++) {
91 pagetable[0x200 + i] = (tseg_start + 0x2000 + i * 0x1000) | MAP_FLAGS;
94 /* Map 0x300000 -> 0x200000, so we can copy our code out of
95 * RAM the first time around */
96 for (i = 0; i < 256; i++) {
97 pagetable[0x300 + i] = (0x200000 + i * 0x1000) | MAP_FLAGS;
101 return pagedirectory;
109 if (!entry_initialized)
110 pt_setup(0xA0000, 0x1FF80000, 0x80000);
115 set_cr0(get_cr0() | CR0_PG);
119 if (!entry_initialized) {
121 /* If needed, copy in data. */
122 for (bp = (void *)0x200000; (void *)bp < (void *)&_bss; bp++)
123 *bp = *(bp + 0x100000);
124 for (bp = (void *)&_bss; (void *)bp < (void *)&_bssend; bp++)
127 dolog("Paging enabled.");
132 if (!entry_initialized) {
135 entry_initialized = 1;
139 ps_switch_stack(smi_entry, 0x270000);