Got mtab to be able to split up memory ranges
This commit is contained in:
parent
816b44a417
commit
271ee98e27
8
main.asm
8
main.asm
@ -4,10 +4,14 @@ org 0x0100
|
|||||||
jmp main
|
jmp main
|
||||||
|
|
||||||
main:
|
main:
|
||||||
call mm_print
|
mov ax,0x1000
|
||||||
|
mov bx,0x0000
|
||||||
|
mov cx,0x0800
|
||||||
|
call mtab_set
|
||||||
|
call mtab_dump
|
||||||
ret
|
ret
|
||||||
|
|
||||||
%include "kprintf.asm"
|
%include "kprintf.asm"
|
||||||
|
|
||||||
; mem MUST be last because it will write after it
|
; mem MUST be last because it will write after itself
|
||||||
%include "mem.asm"
|
%include "mem.asm"
|
||||||
|
133
mem.asm
133
mem.asm
@ -5,79 +5,108 @@
|
|||||||
; 03 - reserved, like BIOS code or tables for the cpu
|
; 03 - reserved, like BIOS code or tables for the cpu
|
||||||
; 04 - unusable
|
; 04 - unusable
|
||||||
|
|
||||||
; search memory table for a item matching a segment addr
|
; return the addr of the mtab
|
||||||
; in: ax: segment
|
; out: es:bx
|
||||||
; out: bp: table start address
|
mtab_ref:
|
||||||
; si: table item offset
|
|
||||||
; ax: offset from begin of memory block
|
|
||||||
mm_findtab:
|
|
||||||
push bx
|
|
||||||
push cx
|
|
||||||
push cs
|
push cs
|
||||||
pop ds
|
pop es
|
||||||
mov cx,0x0000
|
mov bx,mtab
|
||||||
mov bp,memtab
|
|
||||||
mov si,0x0000
|
|
||||||
.loop:
|
|
||||||
add cx,[bp+si+0x00]
|
|
||||||
cmp cx,ax
|
|
||||||
jnbe .end
|
|
||||||
mov bx,[bp+si+0x02]
|
|
||||||
mov si,bx
|
|
||||||
jmp .loop
|
|
||||||
.end:
|
|
||||||
sub cx,[bp+si+0x00]
|
|
||||||
sub ax,cx
|
|
||||||
pop cx
|
|
||||||
pop bx
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; finds a place for a new item in the mm table
|
; finds a place for a new item in the mm table
|
||||||
; out: si
|
; out: bx
|
||||||
mm_taballoc:
|
mtab_alloc:
|
||||||
push ax
|
push ax
|
||||||
mov bp,memtab
|
call mtab_ref
|
||||||
mov si,0x0000
|
|
||||||
.loop:
|
.loop:
|
||||||
cmp WORD [bp+si],0x0000
|
cmp WORD [es:bx],0x0000
|
||||||
je .end
|
je .end
|
||||||
mov ax,si
|
add bx,0x0010
|
||||||
add ax,0x0010
|
|
||||||
mov si,ax
|
|
||||||
jmp .loop
|
jmp .loop
|
||||||
.end:
|
.end:
|
||||||
pop ax
|
pop ax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; force-sets the type of a memory block (dangerous)
|
|
||||||
; in: ax: segment
|
; in: ax: segment
|
||||||
; bl: memory type
|
; bh: task id (0 for non-task memory)
|
||||||
; cx: length in 16 byte blocks
|
; bl: memory type (see enum at top of file)
|
||||||
mm_setup_range:
|
; cx: number of 16-byte blocks
|
||||||
push dx
|
mtab_set:
|
||||||
call mm_findtab ; i'll refer the item returned in si as 'base'
|
|
||||||
mov dx,[bp+si] ; get size from base
|
|
||||||
push si
|
|
||||||
; duplicate the base
|
|
||||||
call mm_taballoc
|
|
||||||
mov di,si
|
|
||||||
pop si
|
|
||||||
|
|
||||||
push ds
|
push ds
|
||||||
pop es
|
push cx ; length of current item
|
||||||
push cx
|
push dx ; cumulative position
|
||||||
mov cx,0x0010
|
push bx ; pointer to mtab item
|
||||||
rep movsb ; copies 0x10 bytes from ES:SI to DS:DI
|
|
||||||
|
call mtab_ref
|
||||||
|
mov dx,0x0000
|
||||||
|
push bx ; use as iterator, restoring base value afterwards
|
||||||
|
.findbase: ; we pick the mtab item where our segment lies in
|
||||||
|
mov cx,[es:bx]
|
||||||
|
add dx,cx
|
||||||
|
cmp dx,ax
|
||||||
|
jnbe .dupbase
|
||||||
|
add bx,0x0010
|
||||||
|
jmp .findbase
|
||||||
|
.dupbase: ; we duplicate it, so we potentially have one after and one before our new item
|
||||||
|
mov si,bx
|
||||||
|
call mtab_alloc
|
||||||
|
mov di,bx
|
||||||
|
pop bx
|
||||||
|
|
||||||
|
push si ; backup because movsw increments them
|
||||||
|
push di ; ^
|
||||||
|
push cx ; counter for movsb
|
||||||
|
mov cx,0x08 ; a mtab item is 8 words = 16 bytes
|
||||||
|
push es
|
||||||
|
pop ds
|
||||||
|
rep movsw
|
||||||
pop cx
|
pop cx
|
||||||
|
pop di
|
||||||
|
pop si
|
||||||
|
.resizebase1:
|
||||||
|
push ax ; size = [Segment ax] - ([End addr dx] - [Length cx])
|
||||||
|
sub ax,dx
|
||||||
|
add ax,cx
|
||||||
|
mov [si],ax
|
||||||
|
pop ax
|
||||||
|
.resizebase2:
|
||||||
|
push dx
|
||||||
|
sub dx,ax
|
||||||
|
mov [di],dx
|
||||||
|
pop dx
|
||||||
|
.insert:
|
||||||
|
push bx
|
||||||
|
call mtab_alloc
|
||||||
|
mov dx,bx
|
||||||
|
pop bx
|
||||||
|
.base1_link:
|
||||||
|
push ax
|
||||||
|
mov ax,dx
|
||||||
|
sub ax,bx ; addr are relative to mtab start
|
||||||
|
mov [si+02],ax
|
||||||
|
pop ax
|
||||||
|
.new_link:
|
||||||
|
push ax
|
||||||
|
mov ax,di
|
||||||
|
sub ax,bx ; addr are relative to mtab start
|
||||||
|
mov di,dx
|
||||||
|
mov [di+02],ax
|
||||||
|
pop ax
|
||||||
|
|
||||||
|
pop bx
|
||||||
|
mov [di+04],bx
|
||||||
|
|
||||||
pop dx
|
pop dx
|
||||||
|
pop cx
|
||||||
|
|
||||||
|
pop ds
|
||||||
ret
|
ret
|
||||||
|
|
||||||
mm_print:
|
mtab_dump:
|
||||||
push cs
|
push cs
|
||||||
pop ds
|
pop ds
|
||||||
mov cx,0x0000
|
mov cx,0x0000
|
||||||
mov bp,memtab
|
mov bp,mtab
|
||||||
mov si,0x0000
|
mov si,0x0000
|
||||||
|
|
||||||
.loop:
|
.loop:
|
||||||
@ -132,7 +161,7 @@ mm_print:
|
|||||||
|
|
||||||
; pre-filled table for memory management
|
; pre-filled table for memory management
|
||||||
align 16
|
align 16
|
||||||
memtab:
|
mtab:
|
||||||
; interrupt vector table
|
; interrupt vector table
|
||||||
dw 0x0040
|
dw 0x0040
|
||||||
dw 0x0010
|
dw 0x0010
|
||||||
|
Loading…
Reference in New Issue
Block a user