]> Joshua Wise's Git repositories - netwatch.git/blame - aseg-paging/pagingstub.c
add serial output to aseg-paging
[netwatch.git] / aseg-paging / pagingstub.c
CommitLineData
9e2a82e4
JP
1#include <io.h>
2#include <smram.h>
3#include <video_defines.h>
4#include <minilib.h>
5#include <smi.h>
6#include <pci-bother.h>
7#include "../net/net.h"
8#include "vga-overlay.h"
9
10#include "vm_flags.h"
11#include "pagetable.h"
12
13void set_cr0(unsigned int);
14
15extern int entry_initialized;
16extern int _bss, _bssend, _end;
17void smi_entry();
18#define get_cr0() \
19 ({ \
20 register unsigned int _temp__; \
21 asm volatile("mov %%cr0, %0" : "=r" (_temp__)); \
22 _temp__; \
23 })
24
25
26#define set_cr3(value) \
27 { \
28 register unsigned int _temp__ = (value); \
29 asm volatile("mov %0, %%cr3" : : "r" (_temp__)); \
30 }
31#define CR0_PG 0x80000000
32
33#define MAP_FLAGS (PTE_PRESENT | PTE_READ_WRITE)
34
35void * pt_setup(int smbase) {
36 int i;
37 outb(0x80, 0x51);
38
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);
43
44 /* Clear out the page directory except for one entry pointing to the
45 * page table, and clear the page table entirely. */
46 outb(0x80, 0x52);
47 pagedirectory[0] = (smbase + 0x1000) | PTE_PRESENT | PTE_READ_WRITE;
48 outb(0x80, 0x53);
49 for (i = 1; i < 1024; i++)
50 {
51 pagedirectory[i] = 0;
52 }
53
54 outb(0x80, 0x54);
55 for (i = 0; i < 1024; i++)
56 {
57 pagetable[i] = 0;
58 }
59 outb(0x80, 0x55);
60
61 /* The page at 0x10000 - 0x10FFF points to the SMI entry point,
62 * SMBASE + 0x8000. */
63 pagetable[16] = (0x8000 + smbase) | MAP_FLAGS;
64
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
67 * region. */
68
69 for (i = 0; i < 8; i++)
70 {
71 pagetable[17 + i] = (i * 0x1000 + smbase) | MAP_FLAGS;
72 }
73
74 for (i = 0; i < 6; i++)
75 {
76 pagetable[25 + i] = (smbase + 0x9000 + i * 0x1000) | MAP_FLAGS;
77 }
78
79 outb(0x80, 0x56);
80 /* Map 0xA8000 to itself. */
81
82 for (i = 0; i < 32; i++) {
83 pagetable[0xA0 + i] = (0xA0000 + i * 0x1000) | MAP_FLAGS;
84 }
85
86 /* Map 0x200000 to TSEG */
87 for (i = 0; i < 128; i++) {
88 pagetable[0x200 + i] = (0x1FF80000 + i * 0x1000) | MAP_FLAGS;
89 }
90
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;
95 */
96 pagetable[0x200 + i] = (0x200000 + i * 0x1000) | MAP_FLAGS;
97 }
98
99 outb(0x80, 0x57);
100 return pagedirectory;
101}
102
103void c_entry(void)
104{
105// unsigned char *bp;
106
107 outb(0x80, 0x41);
108 char * pagedir = pt_setup(0xA0000);
109 outb(0x80, 0x43);
110 set_cr3((int)pagedir);
111 outb(0x80, 0xA5);
112
113 /* Turn paging on */
114 set_cr0(get_cr0() | CR0_PG);
115 outb(0x80, 0xAA);
116 if (!entry_initialized) {
117 outb(0x80, 0xAB);
118/*
119 for (bp = (void *)0x200000; (void *)bp < (void *)&_bss; bp++)
120 *bp = *(bp + 0x100000);
121
122 for (bp = (void *)&_bss; (void *)bp < (void *)&_bssend; bp++)
123 *bp = 0;
124 */
125 }
126
127 smi_entry();
128}
This page took 0.033822 seconds and 4 git commands to generate.