3 #include <video_defines.h>
6 #include <pci-bother.h>
7 #include "../net/net.h"
8 #include "vga-overlay.h"
11 #include "pagetable.h"
13 void set_cr0(unsigned int);
15 extern int entry_initialized;
16 extern int _bss, _bssend, _end;
20 register unsigned int _temp__; \
21 asm volatile("mov %%cr0, %0" : "=r" (_temp__)); \
26 #define set_cr3(value) \
28 register unsigned int _temp__ = (value); \
29 asm volatile("mov %0, %%cr3" : : "r" (_temp__)); \
31 #define CR0_PG 0x80000000
33 #define MAP_FLAGS (PTE_PRESENT | PTE_READ_WRITE)
35 void * pt_setup(int smbase) {
39 /* The page directory and page table live at SMBASE and SMBASE + 0x1000,
40 * respectively; clear them. */
41 int * pagedirectory = (int *) smbase;
42 int * pagetable = (int *) (smbase + 0x1000);
44 /* Clear out the page directory except for one entry pointing to the
45 * page table, and clear the page table entirely. */
47 pagedirectory[0] = (smbase + 0x1000) | PTE_PRESENT | PTE_READ_WRITE;
49 for (i = 1; i < 1024; i++)
55 for (i = 0; i < 1024; i++)
61 /* The page at 0x10000 - 0x10FFF points to the SMI entry point,
63 pagetable[16] = (0x8000 + smbase) | MAP_FLAGS;
65 /* 0x11000 to 0x1EFFF map to the rest of ASEG up to SMBASE + 0xF000;
66 * the page containing the saved state is not mappped to our code
69 for (i = 0; i < 8; i++)
71 pagetable[17 + i] = (i * 0x1000 + smbase) | MAP_FLAGS;
74 for (i = 0; i < 6; i++)
76 pagetable[25 + i] = (smbase + 0x9000 + i * 0x1000) | MAP_FLAGS;
80 /* Map 0xA8000 to itself. */
82 for (i = 0; i < 32; i++) {
83 pagetable[0xA0 + i] = (0xA0000 + i * 0x1000) | MAP_FLAGS;
86 /* Map 0x200000 to TSEG */
87 for (i = 0; i < 128; i++) {
88 pagetable[0x200 + i] = (0x1FF80000 + i * 0x1000) | MAP_FLAGS;
91 /* Map 0x300000 -> 0x200000, so we can copy our code out of
92 * RAM the first time around */
93 for (i = 0; i < 256; i++) {
94 /* pagetable[0x300 + i] = (0x200000 + i * 0x1000) | MAP_FLAGS;
96 pagetable[0x200 + i] = (0x200000 + i * 0x1000) | MAP_FLAGS;
100 return pagedirectory;
105 // unsigned char *bp;
108 char * pagedir = pt_setup(0xA0000);
110 set_cr3((int)pagedir);
114 set_cr0(get_cr0() | CR0_PG);
116 if (!entry_initialized) {
119 for (bp = (void *)0x200000; (void *)bp < (void *)&_bss; bp++)
120 *bp = *(bp + 0x100000);
122 for (bp = (void *)&_bss; (void *)bp < (void *)&_bssend; bp++)