Оптимизация потребления ОЗУ

Теперь для запуска требуется всего 27 мегабайт ОЗУ!
This commit is contained in:
Aren Elchinyan 2024-02-02 18:36:48 +03:00
parent 3a6c3b3ca7
commit d5cb26f9a4
5 changed files with 73 additions and 6 deletions

View File

@ -1,3 +1,3 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_BUILD 0
#define VERSION_BUILD 14

View File

@ -6,10 +6,71 @@
*
*/
#include <LOG.h>
#include <arch.h>
typedef struct __attribute__((packed)) {
uint16_t limit;
uint64_t base;
} gdt_reg_t;
struct gdt_desc {
uint16_t limit;
uint16_t base_low;
uint8_t base_mid;
uint8_t access;
uint8_t granularity;
uint8_t base_hi;
} __attribute__((packed));
static uint64_t kernel_start_ticks = 0;
static uint64_t kernel_ticks = 0;
static gdt_reg_t gdtr;
static struct gdt_desc gdt_descs[] = { { 0 },
{ .limit = 0xffff,
.base_low = 0x0000,
.base_mid = 0x00,
.access = 0b10011011,
.granularity = 0b00000000,
.base_hi = 0x00 },
{ .limit = 0xffff,
.base_low = 0x0000,
.base_mid = 0x00,
.access = 0b10010011,
.granularity = 0b00000000,
.base_hi = 0x00 },
{ .limit = 0xffff,
.base_low = 0x0000,
.base_mid = 0x00,
.access = 0b10011011,
.granularity = 0b11001111,
.base_hi = 0x00 },
{ .limit = 0xffff,
.base_low = 0x0000,
.base_mid = 0x00,
.access = 0b10010011,
.granularity = 0b11001111,
.base_hi = 0x00 },
{ .limit = 0x0000,
.base_low = 0x0000,
.base_mid = 0x00,
.access = 0b10011011,
.granularity = 0b00100000,
.base_hi = 0x00 },
{ .limit = 0x0000,
.base_low = 0x0000,
.base_mid = 0x00,
.access = 0b10010011,
.granularity = 0b00000000,
.base_hi = 0x00 } };
extern void load_gdt(uint64_t gdtr);
uint64_t rdtsc( ) {
unsigned int lo, hi;
@ -41,6 +102,12 @@ uint64_t arch_get_tick_l( ) {
}
void arch_init( ) {
LOG("Установка сегментов\n");
gdtr.limit = (sizeof(gdt_descs) - 1);
gdtr.base = (uint64_t)&gdt_descs;
load_gdt((uint64_t)&gdtr);
LOG("Установка сегментов успешна!\n");
pic_init( );
idt_init( );
cpu_init( );

View File

@ -1,8 +1,8 @@
.global load_gdt
load_gdt:
cli
lgdt (%rdi)
movw $0x30, %ax
lgdt (%rdi) # Загружаем GDT
movw $0x30, %ax # Обновляем GDT
mov %ax, %ds
mov %ax, %es
mov %ax, %fs

View File

@ -334,10 +334,10 @@ void mem_init( ) {
LOG("Размер битовой карты: %u\n", bitmap_size);
alloc_init(mem_frame_alloc(1024), 1024 * BLOCK_SIZE);
LOG("%u мегабайт выделено в динамичную память\n", (256 * 32 * BLOCK_SIZE + BLOCK_SIZE) / 1024 / 1024);
LOG("%u мегабайт выделено в динамичную память\n", (256 * 16 * BLOCK_SIZE + BLOCK_SIZE) / 1024 / 1024);
// Выделяем по 4 мегабайта в аллокатор динамичной памяти
for (uint64_t i = 0; i < 64; i += 8) { mem_add_block(mem_frame_alloc(1024), 1024 * BLOCK_SIZE); }
for (uint64_t i = 0; i < 32; i += 8) { mem_add_block(mem_frame_alloc(1024), 1024 * BLOCK_SIZE); }
mem_merge_all_blocks( );
mem_dump_memory( );

2
run.sh
View File

@ -1,5 +1,5 @@
#!/bin/sh
qemu-system-x86_64 -name "БМПОС" -cpu max -m 1G -smp 1 \
qemu-system-x86_64 -name "БМПОС" -cpu max -m 64M -smp 1 \
-serial file:serial.log \
-drive file=bmosp.hdd,if=none,id=sata_drive -device ahci \
-device virtio-blk-pci,drive=sata_drive --no-reboot \