Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dfa546e

Browse files
committed
Add test/ for test functions.
Fixed some warnings. Add comments. Ready to vmm.
1 parent e376be6 commit dfa546e

File tree

12 files changed

+86
-30
lines changed

12 files changed

+86
-30
lines changed

‎iso/boot/kernel.kernel‎

1.21 KB
Binary file not shown.

‎simplekernel.iso‎

2 KB
Binary file not shown.

‎src/arch/i386/boot/boot.s‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
# This file is a part of MRNIU/SimpleKernel (https://github.com/MRNIU/SimpleKernel).
33
# boot.s for MRNIU/SimpleKernel.
44

5+
# 3.1.1 The layout of Multiboot2 header
6+
# The layout of the Multiboot2 header must be as follows:
7+
# Offset Type Field Name Note
8+
# 0 u32 magic required
9+
# 4 u32 architecture required
10+
# 8 u32 header_length required
11+
# 12 u32 checksum required
12+
# 16-XX tags required
13+
514
# multiboot2 定义
615
.set MULTIBOOT_SEARCH, 32768
716
.set MULTIBOOT_HEADER_ALIGN, 8

‎src/include/libc/stdio.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ extern int printf(const char * fmt, ...);
3232

3333
#define COL_DEBUG light_cyan
3434
#define COL_ERROR light_red
35-
#define COL_INFO green
35+
#define COL_INFO light_green
36+
#define COL_TEST green
3637

3738

3839
#endif

‎src/include/mm/pmm.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
#include "assert.h"
88

99
// 物理页帧数组长度
10-
static uint32_t phy_pages_count;
10+
static uint64_t phy_pages_count;
1111

1212
// 可用物理内存页起始地址
13-
static uint32_t pmm_addr_start;
13+
// static uint32_t pmm_addr_start;
1414

1515
// 可用物理内存页结束地址
16-
static uint32_t pmm_addr_end;
16+
// static uint32_t pmm_addr_end;
1717

1818
// 物理内存页面管理的栈
19-
static uint32_t pmm_stack[PAGE_MAX_SIZE+1];
19+
static uint32_t pmm_stack[PAGE_MAX_SIZE+1];//内存占用 64 pages
2020

2121
// 物理内存管理的栈指针
2222
static uint32_t pmm_stack_top;
2323

24-
void pmm_init(structmultiboot_tag*tag) {
24+
void pmm_init(multiboot_tag_t*tag) {
2525
multiboot_memory_map_entry_t * mmap;
2626
mmap = ((struct multiboot_tag_mmap *) tag)->entries;
2727
for (; (uint8_t *) mmap< (uint8_t *) tag + tag->size;
@@ -31,8 +31,8 @@ void pmm_init(struct multiboot_tag *tag) {
3131
if ((unsigned) mmap->type == MULTIBOOT_MEMORY_AVAILABLE
3232
&& (unsigned) (mmap->addr & 0xffffffff) == 0x100000) {
3333
// 把内核结束位置到结束位置的内存段,按页存储到页管理栈里
34-
uint32_t page_addr = (mmap->addr);
35-
uint32_t length = (mmap->len);
34+
uint64_t page_addr = (mmap->addr);
35+
uint64_t length = (mmap->len);
3636
while (page_addr < length && page_addr <= PMM_MAX_SIZE) {
3737
pmm_free_page(page_addr);
3838
page_addr += PMM_PAGE_SIZE;
@@ -45,14 +45,14 @@ void pmm_init(struct multiboot_tag *tag) {
4545
return;
4646
}
4747

48-
uint32_t pmm_alloc_page(){
48+
uint32_t pmm_alloc_page(void){
4949
assert(pmm_stack_top != 0);
5050
uint32_t page = pmm_stack[pmm_stack_top--];
5151
return page;
5252
}
5353

54-
void pmm_free_page(uint32_tp){
54+
void pmm_free_page(uint64_tpage){
5555
assert(pmm_stack_top != PAGE_MAX_SIZE);
56-
pmm_stack[++pmm_stack_top] = p;
56+
pmm_stack[++pmm_stack_top] = page;
5757
return;
5858
}

‎src/include/mm/pmm.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ extern uint32_t kernel_end[];
2323

2424

2525
// 初始化内存管理
26-
void pmm_init(structmultiboot_tag*tag);
26+
void pmm_init(multiboot_tag_t*tag);
2727

28+
uint32_t pmm_alloc_page(void);
29+
30+
void pmm_free_page(uint64_t page);
2831
#endif

‎src/include/multiboot2.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "stdint.h"
2323
#include "stdbool.h"
2424
#include "stdio.h"
25-
#include "mm/pmm.h"
2625

2726
/* How many bytes from the start of the file we search for the header. */
2827
#define MULTIBOOT_SEARCH 32768
@@ -91,10 +90,10 @@
9190

9291
#ifndef ASM_FILE
9392

94-
typedef unsigned char multiboot_uint8_t;
95-
typedef unsigned short multiboot_uint16_t;
96-
typedef unsigned int multiboot_uint32_t;
97-
typedef unsigned long long multiboot_uint64_t;
93+
typedef uint8_t multiboot_uint8_t;
94+
typedef uint16_t multiboot_uint16_t;
95+
typedef uint32_t multiboot_uint32_t;
96+
typedef uint64_t multiboot_uint64_t;
9897

9998
struct multiboot_header {
10099
multiboot_uint32_t magic; // Must be MULTIBOOT_MAGIC - see above.
@@ -188,6 +187,7 @@ struct multiboot_tag {
188187
multiboot_uint32_t type;
189188
multiboot_uint32_t size;
190189
};
190+
typedef struct multiboot_tag multiboot_tag_t;
191191

192192
struct multiboot_tag_string {
193193
multiboot_uint32_t type;

‎src/kernel.kernel‎

1.23 KB
Binary file not shown.

‎src/kernel/kernel.c‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// kernel.c for MRNIU/SimpleKernel.
55

66
#include "kernel.h"
7+
#include "../test/test.h"
78

89
// 内核入口
910
void kernel_main(uint32_t magic, uint32_t addr) {
@@ -13,20 +14,9 @@ void kernel_main(uint32_t magic, uint32_t addr) {
1314
idt_init(); // IDT 初始化
1415
clock_init(); // 时钟初始化
1516
keyboard_init(); // 键盘初始化
16-
pmm_init(addr);
17+
pmm_init((multiboot_tag_t*)addr);
1718
showinfo();
18-
19-
uint32_t allc_addr = NULL;
20-
printk_color(red, "Test Physical Memory Alloc :\n");
21-
allc_addr = pmm_alloc_page();
22-
printk_color(red, "Alloc Physical Addr: 0x%08X\n", allc_addr);
23-
allc_addr = pmm_alloc_page();
24-
printk_color(red, "Alloc Physical Addr: 0x%08X\n", allc_addr);
25-
allc_addr = pmm_alloc_page();
26-
printk_color(red, "Alloc Physical Addr: 0x%08X\n", allc_addr);
27-
allc_addr = pmm_alloc_page();
28-
printk_color(red, "Alloc Physical Addr: 0x%08X\n", allc_addr);
29-
19+
test();
3020

3121
while(1);
3222

‎src/kernel/multiboot2.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
#include "multiboot2.h"
8+
#include "mm/pmm.h"
89

910
void print_MULTIBOOT_TAG_TYPE_CMDLINE(struct multiboot_tag *tag){
1011
printk_color(COL_DEBUG, "[DEBUG] ");

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /