152 lines
2.4 KiB
Z80 Assembly
152 lines
2.4 KiB
Z80 Assembly
|
.global _start
|
||
|
|
||
|
_start:
|
||
|
ld hl, syscall
|
||
|
ld a, 0xc3
|
||
|
ld (0xdffd), a
|
||
|
ld (0xdffe), hl
|
||
|
call scan_cards
|
||
|
call vmem_init
|
||
|
call pmem_init
|
||
|
call proc_map_init
|
||
|
ld c, 0
|
||
|
call get_frame
|
||
|
push bc
|
||
|
ld ix, empty_pagemap
|
||
|
call pmap_load
|
||
|
pop bc
|
||
|
ld c, b
|
||
|
ld b, 4
|
||
|
init_page_map_loop:
|
||
|
ld a, b
|
||
|
add a, 7
|
||
|
push bc
|
||
|
ld b, c
|
||
|
ld c, a
|
||
|
ld e, a
|
||
|
ld d, 0
|
||
|
call set_frame
|
||
|
pop bc
|
||
|
djnz init_page_map_loop
|
||
|
call tasking_init
|
||
|
call find_disk
|
||
|
ld hl, init_str
|
||
|
call read_init
|
||
|
ld hl, 0x8000
|
||
|
after_file_pos:
|
||
|
push hl
|
||
|
pop iy
|
||
|
ld l, (iy+0x1C) ; Load IX with the start of the program headers in memory
|
||
|
ld h, (iy+0x1D) ; Load IX with the start of the program headers in memory
|
||
|
push hl
|
||
|
pop ix
|
||
|
push iy
|
||
|
pop bc
|
||
|
add ix, bc
|
||
|
ld a, (iy+0x2C) ; load B with the number of program headers
|
||
|
ld b, a
|
||
|
phead_loop:
|
||
|
ld a, (ix+0)
|
||
|
cp 1
|
||
|
jp NZ, next_seg
|
||
|
push bc
|
||
|
ld c, (ix+20)
|
||
|
ld b, (ix+21)
|
||
|
; b = if c > 0 || b & 0xF > 0 {
|
||
|
; (b & 0xF0) + 0x10
|
||
|
; } else {
|
||
|
; b & 0xF0
|
||
|
; } >> 4
|
||
|
ld a, c
|
||
|
cp 0
|
||
|
jp z, cmp2
|
||
|
jp blk1
|
||
|
cmp2:
|
||
|
ld a, b
|
||
|
and 0xF
|
||
|
cp 0
|
||
|
jp z, blk2
|
||
|
blk1:
|
||
|
ld a, b
|
||
|
and 0xF0
|
||
|
add a, 0x10
|
||
|
ld b, a
|
||
|
jp end1
|
||
|
blk2:
|
||
|
ld a, b
|
||
|
and 0xF0
|
||
|
ld b, a
|
||
|
end1:
|
||
|
srl b
|
||
|
srl b
|
||
|
srl b
|
||
|
srl b
|
||
|
ld c, (ix+9)
|
||
|
srl c
|
||
|
srl c
|
||
|
srl c
|
||
|
srl c
|
||
|
push iy
|
||
|
push ix
|
||
|
push de
|
||
|
page_alloc_loop:
|
||
|
push bc
|
||
|
call get_free_frame
|
||
|
ld b, c
|
||
|
ld d, h
|
||
|
ld e, l
|
||
|
pop hl
|
||
|
ld c, l
|
||
|
push hl
|
||
|
call set_frame
|
||
|
pop bc
|
||
|
inc c
|
||
|
djnz page_alloc_loop
|
||
|
pop de
|
||
|
pop ix
|
||
|
pop iy
|
||
|
;Zero out the segments place in memory
|
||
|
ld c, (ix+20) ; Load the byte counter with the number of bytes to zero out
|
||
|
ld b, (ix+21)
|
||
|
ld e, (ix+8) ; Load the destination & source address register with the destination location of the segment in memory
|
||
|
ld d, (ix+9)
|
||
|
ld h, d
|
||
|
ld l, e
|
||
|
ld (hl), 0 ; Zero out the firts byte in the segment ( Acts as a 'seed' for the zeroing )
|
||
|
ldir
|
||
|
ld c, (ix+16) ; Load the byte counter with the number of bytes to transfer
|
||
|
ld b, (ix+17)
|
||
|
ld l, (ix+4) ; Load the source address register with the memory address if the segment data
|
||
|
ld h, (ix+5)
|
||
|
push iy
|
||
|
pop de
|
||
|
add hl, de
|
||
|
ld e, (ix+8) ; Load the destination address register with the destination location of the segment in memory
|
||
|
ld d, (ix+9)
|
||
|
ldir; Do the transfer
|
||
|
pop bc
|
||
|
next_seg:
|
||
|
ld de, 32
|
||
|
add ix, de
|
||
|
dec b
|
||
|
ld a, b
|
||
|
jp nz, phead_loop
|
||
|
ld l, (iy+0x18) ; Load HL with the program entry point
|
||
|
ld h, (iy+0x19) ; Load HL with the program entry point
|
||
|
ld ix, init_pagemap
|
||
|
call pmap_set
|
||
|
ld ix, empty_pagemap
|
||
|
call pmap_load
|
||
|
ld iy, init_pagemap
|
||
|
call new_process
|
||
|
call yield
|
||
|
halt
|
||
|
|
||
|
init_str: .asciz "init.elf"
|
||
|
|
||
|
empty_pagemap:
|
||
|
.ds.b 36
|
||
|
init_pagemap:
|
||
|
.ds.b 36
|
||
|
|