-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.cpp
More file actions
96 lines (88 loc) · 2.14 KB
/
Copy pathmain.cpp
File metadata and controls
96 lines (88 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <Windows.h>
#include "stdio.h"
#include "intrin.h"
#include "typedef.h"
#include "io.h"
#include "vga.h"
#include "C++.h"
#include "gdt.h"
#include "idt.h"
#include "pci.h"
#include "cpu.h"
#include "tss.h"
#include "mmu.h"
#include "process.h"
#include "trap.h"
#include "8253.h"
#include "8259.h"
#include "keyboard.h"
#include "rtc.h"
#include "bios.h"
#include "system.h"
#include "liballoc.h"
#include "paging.h"
CPU cpu;
uint32 get_mem_info(memory_info& meminfo)
{
BIOS bios;
bios.get_mem_info(meminfo);
uint64 memsize = 0;
for (int i = 0; i < meminfo.map_count; i++)
{
uint64 length = meminfo.mem_maps[i].length;
uint64 begin = meminfo.mem_maps[i].base_addr;
uint64 end = begin + length;
continue;
printf("%d %08X-%08X %08X-%08X %08X-%08X %d ",
i,
(uint32)(begin >> 32), (uint32)(begin & 0xffffffff),
(uint32)(end >> 32), (uint32)(end & 0xffffffff),
(uint32)(length >> 32), (uint32)(length & 0xffffffff),
meminfo.mem_maps[i].type);
switch (meminfo.mem_maps[i].type)
{
case MEMTYPE_RAM:
printf("RAM\n");
if (memsize < end && end < 0x100000000I64)
{
memsize = end;
}
break;
case MEMTYPE_RESERVED: printf("RESERVED\n"); break;
case MEMTYPE_ACPI: printf("ACPI\n"); break;
case MEMTYPE_NVS: printf("NVS\n"); break;
default: printf("\n"); break;
}
}
return memsize;
}
#include "list.h"
void main(uint32 kernel_image_size)
{
puts("\nHello world\n", 30);
puts("Shellcode OS is starting...\n", 30);
CppInit();
//callbios 要求内存地址位于1M一下,
//因此,此处从栈(esp<0x00090000)中分配meminfo
memory_info meminfo;
uint32 memsize = get_mem_info(meminfo);
printf("memsize=%08X(%dMb)\n", memsize, memsize >> 20);
System.Init(kernel_image_size, &meminfo);
uint32 system_stack = System.get_stack();
__asm mov esp, system_stack
//
//LIST<PROCESS>* process_list = new LIST<PROCESS>();
//PROCESS* proc = new PROCESS();
//printf("process_list=%08X process=%08X\n", process_list, (uint32)proc);
//process_list->insert_head(proc);
//process_list->remove_tail();
//delete process_list;
//delete proc;
//load_minidump();
//load_shellcode();
//
_enable();
panic("");
_enable();
__asm jmp $
}