Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified build/AUTO.ISO
Binary file not shown.
21 changes: 1 addition & 20 deletions src/Kernel/KStart16.ZC
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ SYS_RUN_LEVEL:: DU32 0;
#assert SYS_COMPILE_TIME + sizeof(CDate) + sizeof(CZXE) < DVD_BLK_SIZE

MEM_BOOT_BASE:: DU32 0; //Offset from start used by reboot
MEM_E801:: DU16 0, 0;
MEM_E820:: DU8 MEM_E820_ENTRIES_NUM * sizeof(CMemE820) DUP (0);
MEM_PHYSICAL_SPACE:: DU64 0;
SYS_GDT_PTR:: DU16 sizeof(CGDT) - 1;
Expand Down Expand Up @@ -244,19 +243,6 @@ GET_IP: POP BX
BTS U32 [SYS_RUN_LEVEL], RLf_VESA
@@35:

//Get E801 memory map.
//Output: AX = Memory between 1MiB and 16MiB in KiB (max 0x3C00 == 15 MiB)
// BX = Memory after 16MiB until first memory hole in 64KiB blocks.
XOR CX, CX
XOR DX, DX
MOV AX, 0xE801
INT 0x15
JCXZ @@40 //if CX and DX are zero, use AX and BX instead.
MOV AX, CX
MOV BX, DX
@@40: MOV U16 [MEM_E801], AX
MOV U16 [MEM_E801+2], BX

//Get E820 memory map.
MOV CX, MEM_E820_ENTRIES_NUM - 1 //Leave one to terminate
XOR EBX, EBX
Expand All @@ -279,14 +265,9 @@ GET_IP: POP BX
SUB SP, 2
@@50: ADD SP, 2 //if called failed we want to nullify the PUSHed CX value.

//Find how much space to map, start with E801 limit.
//Find max of E820 to set mapped space.
XOR EAX, EAX
MOV AX, [MEM_E801+2]
SHL EAX, 16
ADD EAX, SYS_16MEG_AREA_LIMIT
XOR EDX, EDX

//Find max of E820 to set mapped space.
MOV SI, MEM_E820
@@55: MOV CL, CMemE820.type[SI]
TEST CL, CL
Expand Down
3 changes: 2 additions & 1 deletion src/Kernel/KStart64.ZC
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ USE64

//************************************
SYS_RAM_REBOOT:: //This gets copied high. $LK,"SYS_RAM_REBOOT",A="FF:::/System/Boot/BootRAM.ZC,SYS_RAM_REBOOT:2"$
MOV EAX, I32 SYS_BOOT_STACK //Not RIP-relative, as this runs from the copy.
PUSH U32 CGDT.ds //stack seg
PUSH U32 [SYS_BOOT_STACK]//stack
PUSH U32 [RAX] //stack
PUSH U32 0 //flags
PUSH U32 CGDT.cs32
LEA RAX, [@@10]
Expand Down
1 change: 0 additions & 1 deletion src/Kernel/KernelA.HH
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ class CKernel

U0 start;
U32 boot_base;
U16 mem_E801[2];
CMemE820 mem_E820[MEM_E820_ENTRIES_NUM];
U64 mem_physical_space;
CSysLimitBase sys_gdt_ptr;
Expand Down
15 changes: 14 additions & 1 deletion src/Kernel/Memory/BlkPool.ZC
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,20 @@ U0 BlkPoolsInit()
code_heap_limit = 0x80000000;

i = code_heap_limit - SYS_16MEG_AREA_LIMIT; //See $LK,"RLf_16MEG_SYS_CODE_BP",A="FF:::/Kernel/Memory/PageTables.ZC,RLf_16MEG_SYS_CODE_BP"$
BlkPoolAdd(sys_code_bp, SYS_16MEG_AREA_LIMIT, i >> MEM_PAG_BITS);
while (m20->type)
{//The memory below the limit can have holes, so only add the usable E820 ranges.
if (m20->type == MEM_E820t_USABLE)
{
lo = m20->base;
hi = m20->base + m20->len;
lo = CeilI64(MaxI64(lo, SYS_16MEG_AREA_LIMIT), MEM_PAG_SIZE);
hi = FloorI64(MinI64(hi, code_heap_limit), MEM_PAG_SIZE);
if (lo < hi)
BlkPoolAdd(sys_code_bp, lo, (hi - lo) >> MEM_PAG_BITS);
}
m20++;
}
m20 = MEM_E820;
mem_heap_limit = i + SYS_16MEG_AREA_LIMIT - 1;

if (code_heap_limit<total)
Expand Down
10 changes: 3 additions & 7 deletions src/Kernel/Memory/MemPhysical.ZC
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,10 @@ U0 UncachedAliasAlloc() //Make uncached alias for 4 lowest Gig.
}

I64 MemBIOSTotal()
{//Returns max of either E801 or E820 mem map.
I64 total01 = 0x100000, total20 = 0;
U16 *mem01 = MEM_E801;
{//Returns total usable memory in the E820 mem map.
I64 total20 = 0;
CMemE820 *mem20 = MEM_E820;

total01 += mem01[0] * 1024; //First U16 is mem between 1MiB and 16 MiB in KiB.
total01 += mem01[1] * 64 * 1024;//Second U16 is mem above 16MiB (until it encounters a hole) in 64KiB blocks.

if (mem20->type)
{
while (mem20->type)
Expand All @@ -188,7 +184,7 @@ I64 MemBIOSTotal()
mem20++;
}
}
return MaxI64(total01, total20);
return total20;
}

I64 Scale2Mem(I64 min, I64 max, I64 limit=2*1024*1024*1024)
Expand Down
58 changes: 42 additions & 16 deletions src/Kernel/Memory/PageTables.ZC
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,52 @@ SYS_INIT_PAGE_TABLES::
RET

SYS_INIT_16MEG_SYS_CODE_BP::
// Init sys_code_bp to BIOS E801 lowest 16Meg value.
// Init sys_code_bp to the BIOS E820 usable memory below 16Meg.
// $LK,"BlkPoolsInit",A="MN:BlkPoolsInit"$() adds the rest.
MOV U32 [SYS_CODE_BP], SYS_FIXED_AREA + CSysFixedArea.sys_code_bp
MOV U32 [SYS_CODE_BP + 4], 0

MOV U32 [SYS_DATA_BP], 0
MOV U32 [SYS_DATA_BP + 4], 0

XOR EAX, EAX
MOV AX, U16 [MEM_E801] //1 Kb blocks between 1M and 16M
SHL EAX, 10
ADD EAX, 0x100000
MOV ESI, MEM_E820
JMP @@10
@@05: ADD ESI, sizeof(CMemE820)
@@10: MOV AL, U8 CMemE820.type[ESI]
TEST AL, AL
JNZ @@15
BTS U32 [SYS_RUN_LEVEL], RLf_16MEG_SYS_CODE_BP
RET

@@15: CMP AL, MEM_E820t_USABLE
JNE @@05
CMP U32 CMemE820.base + 4 [ESI], 0
JNE @@05
MOV EDI, U32 CMemE820.base[ESI]
CMP EDI, SYS_16MEG_AREA_LIMIT
JAE @@05

//Clip the range to between the page tables and 16Meg, whole pages only.
MOV EAX, EDI
XOR EDX, EDX
ADD EAX, U32 CMemE820.len[ESI]
ADC EDX, U32 CMemE820.len + 4 [ESI]
JNZ @@20
CMP EAX, SYS_16MEG_AREA_LIMIT
JBE @@25
@@20: MOV EAX, SYS_16MEG_AREA_LIMIT
@@25: CMP EDI, U32 [MEM_HEAP_BASE]
JAE @@30
MOV EDI, U32 [MEM_HEAP_BASE]
@@30: ADD EDI, MEM_PAG_SIZE - 1
AND EDI, ~(MEM_PAG_SIZE - 1)
AND EAX, ~(MEM_PAG_SIZE - 1)
SUB EAX, EDI
JBE @@05

//EDI=BASE EAX=SIZE
TEST U8 [SYS_MEM_INIT_FLAG], 1
JZ @@05
JZ @@35
PUSH EAX
PUSH EDI
MOV ECX, EAX
Expand All @@ -180,20 +208,18 @@ SYS_INIT_16MEG_SYS_CODE_BP::
POP EDI
POP EAX

@@05: SHR EAX, MEM_PAG_BITS
MOV ESI, SYS_FIXED_AREA + CSysFixedArea.sys_code_bp
MOV EBX, U32 CBlkPool.mem_free_list[ESI]
MOV U32 CMemBlk.next [EDI], EBX
@@35: SHR EAX, MEM_PAG_BITS
MOV EBX, SYS_FIXED_AREA + CSysFixedArea.sys_code_bp
MOV ECX, U32 CBlkPool.mem_free_list[EBX]
MOV U32 CMemBlk.next [EDI], ECX
MOV U32 CMemBlk.next + 4 [EDI], 0
MOV U32 CBlkPool.mem_free_list [ESI], EDI
MOV U32 CBlkPool.mem_free_list + 4 [ESI], 0
MOV U32 CBlkPool.mem_free_list [EBX], EDI
MOV U32 CBlkPool.mem_free_list + 4 [EBX], 0
MOV U32 CMemBlk.mb_signature[EDI], MBS_UNUSED_SIGNATURE_VAL
MOV U32 CMemBlk.pags[EDI], EAX
SHL EAX, MEM_PAG_BITS
ADD U32 CBlkPool.alloced_u8s[ESI], EAX

BTS U32 [SYS_RUN_LEVEL], RLf_16MEG_SYS_CODE_BP
RET
ADD U32 CBlkPool.alloced_u8s[EBX], EAX
JMP I32 @@05
}

I64 *MemPageTable(U8 *a)
Expand Down
9 changes: 0 additions & 9 deletions src/System/DevInfo.ZC
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public U0 PCIRep()
#help_index "Info;Memory/Info"
public U0 MemBIOSRep()
{//Report the memory ranges reported by the BIOS at boot.
U16 *m01 = MEM_E801;
CMemE820 *m20 = MEM_E820;
CMemRange *tmpmr;

Expand Down Expand Up @@ -143,14 +142,6 @@ public U0 MemBIOSRep()
}
LBtr(&sys_semas[SEMA_DEV_MEM], 0);

if (!IsRaw)
"\n$$PURPLE$$BIOS Memory Report 15:E801$$FG$$\n";
else
"\nBIOS Memory Report 15:E801\n";

"0000000000000000-%016X\n", 0x100000 + m01[0] * 1024 - 1;
"0000000001000000-%016X\n", SYS_16MEG_AREA_LIMIT + m01[1] * 64 * 1024 - 1;

if (m20->type)
{
if (!IsRaw)
Expand Down
33 changes: 0 additions & 33 deletions zealbooter/src/zealbooter.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ struct CKernel {
struct CDate compile_time;
// U0 start
uint32_t boot_base;
uint16_t mem_E801[2];
struct CMemE820 mem_E820[MEM_E820_ENTRIES_NUM];
uint64_t mem_physical_space;
struct CSysLimitBase sys_gdt_ptr;
Expand Down Expand Up @@ -151,34 +150,6 @@ struct CKernel {

extern symbol trampoline, trampoline_end;

struct E801 {
size_t lowermem;
size_t uppermem;
};

static struct E801 get_E801(void) {
struct E801 E801 = {0};

for (size_t i = 0; i < memmap_request.response->entry_count; i++) {
struct limine_memmap_entry *entry = memmap_request.response->entries[i];

if (entry->type == LIMINE_MEMMAP_USABLE) {
if (entry->base == 0x100000) {
if (entry->length > 0xf00000) {
E801.lowermem = 0x3c00;
} else {
E801.lowermem = entry->length / 1024;
}
}
if (entry->base <= 0x1000000 && entry->base + entry->length > 0x1000000) {
E801.uppermem = ((entry->length - (0x1000000 - entry->base)) / 1024) / 64;
}
}
}

return E801;
}

void kmain(void) {
printf("ZealBooter prekernel\n");
printf("____________________\n\n");
Expand Down Expand Up @@ -277,10 +248,6 @@ void kmain(void) {

kernel->sys_pci_buses = 256;

struct E801 E801 = get_E801();
kernel->mem_E801[0] = E801.lowermem;
kernel->mem_E801[1] = E801.uppermem;

kernel->mem_physical_space = 0;

printf("memory map:\n");
Expand Down
Loading