Skip to content

Commit b9976a3

Browse files
committed
Move kernel memory location to a header file from Makefile
1 parent 4835fd0 commit b9976a3

File tree

18 files changed

+35
-52
lines changed

18 files changed

+35
-52
lines changed

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ MINIMAL_DISK = $(BUILD_DIR)/minimal_disk
5555
SRC_APP = $(SRC_DIR)/usr/local/src
5656
BUILD_APP = $(BUILD_DIR)/usr/local/bin
5757

58-
MEMORY_LOCATION_KERNEL = 0xC000
59-
6058
SOURCE_SNAPSHOT="\"$$(git rev-parse --short HEAD)$$(git diff --quiet || echo '_unstaged')\""
6159

6260
# General Assumptions

include/fuzzy/memmgr/layout.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
// Most of the memory layout relies on the fact the kernel is first app
4+
// and kernel's pid is 0.
5+
#define PID_KERNEL 0
6+
7+
#define MEMORY_KERNEL_LOCATION 0xC000
8+
#define MEMORY_KERNEL_SIZE 0xFFFF
9+
10+
#define MEMORY_APPBASE_LOCATION 0x20000
11+
#define MEMORY_APP_SIZE 0x0FFFF
12+
13+
// pid starts from 1
14+
#define memmgr_app_abs_location(pid) ((pid)!=0?(MEMORY_APPBASE_LOCATION+((pid)-1)*MEMORY_APP_SIZE):MEMORY_KERNEL_LOCATION)
15+
#define memmgr_app_size(pid) (MEMORY_APP_SIZE)

src/bootloader/Makefile.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ $(bt_stage2).elf: $(SRC_BOOTLOADER)/stage2.asm $(SRC_BOOTLOADER)/stage2.c $(INCL
2828
-D SECTOR_START_KERNEL=$(SECTOR_START_KERNEL) \
2929
-D SECTOR_COUNT_KERNEL=$(SECTOR_COUNT_KERNEL) \
3030
-D MEMORY_STATIC_LIBRARY=$(MEMORY_STATIC_LIBRARY) \
31-
-D MEMORY_LOCATION_KERNEL=$(MEMORY_LOCATION_KERNEL) \
3231
-o $(BUILD_BOOTLOADER)/stage2_c.o $(SRC_BOOTLOADER)/stage2.c
3332
$(LD) -m elf_i386 -Ttext 0x8000 -T linker.ld -o $@ $(BUILD_BOOTLOADER)/stage2_asm.o $(BUILD_BOOTLOADER)/stage2_c.o $(BUILD_LIB_UTILS)/libutils_16 $(BUILD_DRIVERS)/display/libtm_bios $(BUILD_DRIVERS)/disk/libdisk_16
3433
truncate --size=%512 $@

src/bootloader/stage2.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <fuzzy/memmgr/layout.h>
2+
13
#include <lib/utils/color.h>
24
#include <drivers/disk/disk.h>
35
#include <lib/utils/output.h>
@@ -29,12 +31,12 @@ char *get_memdump_8byte(void *address) {
2931

3032
void load_kernel() {
3133
print_log("Loading Kernel");
32-
int err = load_sectors(MEMORY_LOCATION_KERNEL, 0x80, SECTOR_START_KERNEL, SECTOR_COUNT_KERNEL);
34+
int err = load_sectors(MEMORY_KERNEL_LOCATION, 0x80, SECTOR_START_KERNEL, SECTOR_COUNT_KERNEL);
3335
if(err) {
3436
print_log("Failed to load kernel in memory: %d", err);
3537
label_exit();
3638
} else {
37-
print_log("Kernel loaded at 0x%x: %s...", MEMORY_LOCATION_KERNEL, get_memdump_8byte(MEMORY_LOCATION_KERNEL));
39+
print_log("Kernel loaded at 0x%x: %s...", MEMORY_KERNEL_LOCATION, get_memdump_8byte(MEMORY_KERNEL_LOCATION));
3840
}
3941
}
4042

src/drivers/keyboard/Makefile.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
$(SELF_BUILD_DIR)/%.o: $(SELF_SRC_DIR)/%.c $(BUILD_USR_INCLUDE_ALL)
33
mkdir -p $(dir $@)
44
$(KERNEL_CC) -c -o $@ \
5-
-D MEMORY_LOCATION_KERNEL=$(MEMORY_LOCATION_KERNEL) \
65
$<
76

87
$(SELF_BUILD_DIR)/%_asm.o: $(SELF_SRC_DIR)/%.asm

src/fs/Makefile.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
$(SELF_BUILD_DIR)/%.o: $(SELF_SRC_DIR)/%.c $(SELF_INCLUDE_DIR)/%.h
22
mkdir -p $(dir $@)
33
$(KERNEL_CC) -c \
4-
-D MEMORY_LOCATION_KERNEL=$(MEMORY_LOCATION_KERNEL) \
54
-o $@ $<
65

76
$(SELF_BUILD_DIR)/libffs: $(patsubst $(SELF_SRC_DIR)/%.c,$(SELF_BUILD_DIR)/%.o,$(wildcard $(SELF_SRC_DIR)/*.c))

src/fs/ffs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <fuzzy/fs/ffs.h>
22
#include <fuzzy/fs/mbr.h>
3+
#include <fuzzy/memmgr/layout.h>
34
#include <string.h>
45
#include <drivers/disk/disk.h>
56
#include <lib/utils/logging.h>
@@ -8,7 +9,7 @@
89
// TODO: verify partition metadata
910

1011
int partition_read_block(int lba, void *wr_buffer) {
11-
int memory_location = ((int)wr_buffer)+MEMORY_LOCATION_KERNEL;
12+
int memory_location = ((int)wr_buffer)+MEMORY_KERNEL_LOCATION;
1213
int err = load_sectors(memory_location, 0x80, lba, 1);
1314
return err;
1415
}

src/fs/mbr.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#include <fuzzy/fs/ffs.h>
22
#include <fuzzy/fs/mbr.h>
3+
#include <fuzzy/kernel/panic.h>
4+
#include <fuzzy/memmgr/layout.h>
5+
36
#include <drivers/disk/disk.h>
47
#include <lib/utils/logging.h>
5-
#include <fuzzy/kernel/panic.h>
68

79
char _cache_mbrblock[FS_BLOCK_SIZE];
810
int _cache_mbrblock_ready = 0;
911

1012
char *get_mbrblock() {
1113
if(!_cache_mbrblock_ready) {
12-
int memory_location = ((int)_cache_mbrblock)+MEMORY_LOCATION_KERNEL;
14+
int memory_location = ((int)_cache_mbrblock)+MEMORY_KERNEL_LOCATION;
1315
int lba = 0;
1416
int err = load_sectors(memory_location, 0x80, lba, 1);
1517
if (err) {

src/kernel/Makefile.mk

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
MEMORY_LOCATION_APP = 0x20000
2-
31
debug_kernel: $(kernel_core)
42
objdump -b binary -mi386 -Maddr32,data32 -D $<
53
xxd $<
@@ -9,8 +7,6 @@ $(SELF_BUILD_DIR)/%.o: $(SELF_SRC_DIR)/%.c $(BUILD_USR_INCLUDE_ALL)
97
$(KERNEL_CC) -c -o $@ \
108
-D INIT_APPNAME=\"$(INIT_APPNAME)\" \
119
-D __SOURCE_SNAPSHOT__=$(SOURCE_SNAPSHOT) \
12-
-D MEMORY_LOCATION_KERNEL=$(MEMORY_LOCATION_KERNEL) \
13-
-D MEMORY_LOCATION_APP=$(MEMORY_LOCATION_APP) \
1410
$<
1511

1612
$(SELF_BUILD_DIR)/%_asm.o: $(SELF_SRC_DIR)/%.asm

src/kernel/interrupts/Makefile.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
$(SELF_BUILD_DIR)/%.o: $(SELF_SRC_DIR)/%.c $(BUILD_USR_INCLUDE_ALL)
33
mkdir -p $(dir $@)
44
$(KERNEL_CC) -c -o $@ \
5-
-D MEMORY_LOCATION_KERNEL=$(MEMORY_LOCATION_KERNEL) \
65
$<
76

87
$(SELF_BUILD_DIR)/%_asm.o: $(SELF_SRC_DIR)/%.asm

0 commit comments

Comments
 (0)