Alloc'ing from heap we set up.
This commit is contained in:
parent
50d9e63041
commit
517fcba43b
1 changed files with 12 additions and 18 deletions
30
lboot.S
30
lboot.S
|
|
@ -40,8 +40,6 @@ _start: cli
|
||||||
mov $msg_fin, %si
|
mov $msg_fin, %si
|
||||||
call print
|
call print
|
||||||
|
|
||||||
// hang: sleep indefinitely
|
|
||||||
hang: hlt
|
|
||||||
jmp hang
|
jmp hang
|
||||||
|
|
||||||
.set COM1, 0x3F8
|
.set COM1, 0x3F8
|
||||||
|
|
@ -179,22 +177,14 @@ _mhnext: add $24, %si
|
||||||
|
|
||||||
_mhdone: ret
|
_mhdone: ret
|
||||||
|
|
||||||
// alloc: take ECX bytes from usable space in memmap
|
// alloc: take ECX bytes from heap, return ptr in EAX
|
||||||
|
// The allocation does not get marked in the memmap.
|
||||||
// No realignment is performed, so only alloc aligned sizes.
|
// No realignment is performed, so only alloc aligned sizes.
|
||||||
alloc: mov $memmap-24, %si
|
alloc: cmp heap_size, %ecx
|
||||||
_anext: add $24, %si
|
ja _aerr
|
||||||
cmp memmap_end, %si // ran over end of memmap?
|
mov heap_start, %eax
|
||||||
jae _aerr
|
add %ecx, heap_start
|
||||||
cmpl $1, 16(%si)
|
sub %ecx, heap_size
|
||||||
jne _anext
|
|
||||||
// TODO check that entry has enough space
|
|
||||||
cmpl $0, 4(%si) // memory is above 4Gb?
|
|
||||||
jne _aerr
|
|
||||||
mov 0(%si), %eax
|
|
||||||
addl %ecx, 0(%si)
|
|
||||||
adcl $0, 4(%si)
|
|
||||||
subl %ecx, 8(%si)
|
|
||||||
sbbl $0, 12(%si)
|
|
||||||
ret
|
ret
|
||||||
_aerr: mov $msg_aerr, %si
|
_aerr: mov $msg_aerr, %si
|
||||||
call print
|
call print
|
||||||
|
|
@ -247,6 +237,10 @@ gdt: // entry 0: null descriptor
|
||||||
gdt_ptr: .word gdt_size-1
|
gdt_ptr: .word gdt_size-1
|
||||||
.long gdt
|
.long gdt
|
||||||
|
|
||||||
|
// hang: sleep indefinitely
|
||||||
|
hang: hlt
|
||||||
|
jmp hang
|
||||||
|
|
||||||
// Messages to print
|
// Messages to print
|
||||||
msg_start: .asciz "Netboot via fernlader v1 ...\r\n"
|
msg_start: .asciz "Netboot via fernlader v1 ...\r\n"
|
||||||
msg_a20: .asciz " * Enabling A20\r\n"
|
msg_a20: .asciz " * Enabling A20\r\n"
|
||||||
|
|
@ -255,7 +249,7 @@ msg_getmap: .asciz " * Memory Map\r\n"
|
||||||
msg_mkheap: .asciz " * Making Space\r\n"
|
msg_mkheap: .asciz " * Making Space\r\n"
|
||||||
msg_paging: .asciz " * Paging\r\n"
|
msg_paging: .asciz " * Paging\r\n"
|
||||||
msg_fin: .asciz "Finished.\r\n"
|
msg_fin: .asciz "Finished.\r\n"
|
||||||
msg_aerr: .asciz "panic: Unable to allocate memory.\r\n"
|
msg_aerr: .asciz "panic: Out of heap space.\r\n"
|
||||||
|
|
||||||
heap_start: .long 0
|
heap_start: .long 0
|
||||||
heap_size: .long 0
|
heap_size: .long 0
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue