|
|
|
@ -1,5 +1,3 @@
|
|
|
|
|
.equ SEC_BUF_START, 0x400
|
|
|
|
|
.equ PHDR_BUF_START, 0x600
|
|
|
|
|
.equ PHDR_BUF_SEC_SIZE, 5
|
|
|
|
|
.equ STORAGE_SEC, 0x0
|
|
|
|
|
.equ STORAGE_CNT, 0x4
|
|
|
|
@ -11,14 +9,14 @@ _start:
|
|
|
|
|
move.w #0x4, d0 | Find a storage card
|
|
|
|
|
bsr.w find_first_card
|
|
|
|
|
| load the first PHDR_BUF_SEC_SIZE sectors of the ELF kernel binary off the disk
|
|
|
|
|
move.l #PHDR_BUF_START, a1 | Set the destination address to PHDR_BUF_START
|
|
|
|
|
move.l #phdr_buf, a1 | Set the destination address to PHDR_BUF_START
|
|
|
|
|
move.l #0x2, d0 | Set the starting sector number to 2
|
|
|
|
|
move.l #PHDR_BUF_SEC_SIZE, d1 | Set the sector count
|
|
|
|
|
bsr.w read_sectors
|
|
|
|
|
move.l (PHDR_BUF_START + 0x1C), d0 | Load the offset of the program headers in the file
|
|
|
|
|
move.l #PHDR_BUF_START, a1 | Put the address of the program headers in a1
|
|
|
|
|
move.l (phdr_buf + 0x1C), d0 | Load the offset of the program headers in the file
|
|
|
|
|
move.l #phdr_buf, a1 | Put the address of the program headers in a1
|
|
|
|
|
adda.w d0, a1
|
|
|
|
|
move.w (PHDR_BUF_START + 0x2C), d0 | Put the number of program headers - 1 in d0
|
|
|
|
|
move.w (phdr_buf + 0x2C), d0 | Put the number of program headers - 1 in d0
|
|
|
|
|
subq.w #0x1, d0
|
|
|
|
|
phead_loop:
|
|
|
|
|
move.l (a1), d1 | If the type of the program header isn't 1 (LOAD), skip the header
|
|
|
|
@ -45,11 +43,11 @@ move.l d4,d0 | Restore d0 from d4
|
|
|
|
|
next_seg:
|
|
|
|
|
lea (0x20, a1), a1 | Advance a1 to point to the next program header
|
|
|
|
|
dbra d0, phead_loop | If there are more program headers, loop back
|
|
|
|
|
move.l (PHDR_BUF_START + 0x18), a1 | Load the entry point of the program into a1
|
|
|
|
|
move.l (PHDR_BUF_START + 0x1C), d0 | Load the offset of the program headers in the file
|
|
|
|
|
move.l #PHDR_BUF_START, a0 | Put the address of the program headers in a0
|
|
|
|
|
move.l (phdr_buf + 0x18), a1 | Load the entry point of the program into a1
|
|
|
|
|
move.l (phdr_buf + 0x1C), d0 | Load the offset of the program headers in the file
|
|
|
|
|
move.l #phdr_buf, a0 | Put the address of the program headers in a0
|
|
|
|
|
adda.w d0, a0
|
|
|
|
|
move.w (PHDR_BUF_START + 0x2C), d0 | Put the number of program headers in d0
|
|
|
|
|
move.w (phdr_buf + 0x2C), d0 | Put the number of program headers in d0
|
|
|
|
|
jmp (a1) | Jump to the entry point of the program
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -95,7 +93,7 @@ lsr.l #8, d0 | Divide start byte by 512 to compute starting sector
|
|
|
|
|
lsr.l #1, d0
|
|
|
|
|
move.l d0, d5 | Save the starting sector in d5
|
|
|
|
|
move.l #1, d1 | Read the starting sector into the sector buffer
|
|
|
|
|
move.l #SEC_BUF_START, a1
|
|
|
|
|
move.l #sec_buf, a1
|
|
|
|
|
bsr.b read_sectors
|
|
|
|
|
move.l a6, a2 | Load the destination into a2
|
|
|
|
|
move.l d6, d0 | Load the start byte into d0
|
|
|
|
@ -127,7 +125,7 @@ lsl.l #1, d1
|
|
|
|
|
adda.l d1, a2 | Add the number of bytes transferred to a2
|
|
|
|
|
add.l d5, d0 | Compute the end sector number by adding the start and count of the middle sectors
|
|
|
|
|
move.l #1, d1 | Set the number of sectors to read to 1
|
|
|
|
|
move.l #SEC_BUF_START, a1 | Set the read address of the sector to the sector buffer
|
|
|
|
|
move.l #sec_buf, a1 | Set the read address of the sector to the sector buffer
|
|
|
|
|
bsr.b read_sectors | Read the end sector
|
|
|
|
|
move.l d6, d1 | Load the number of remaining bytes into d1
|
|
|
|
|
end_sec_loop: | Transfer the required bytes from the start sector to the destination buffer
|
|
|
|
@ -136,10 +134,11 @@ dbra d1, end_sec_loop
|
|
|
|
|
read_bytes_done:
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.if . != 512
|
|
|
|
|
.org 511
|
|
|
|
|
.byte 0
|
|
|
|
|
.endif
|
|
|
|
|
.section .bss
|
|
|
|
|
sec_buf:
|
|
|
|
|
.ds.b 512
|
|
|
|
|
phdr_buf:
|
|
|
|
|
.ds.b (PHDR_BUF_SEC_SIZE * 512)
|
|
|
|
|
|
|
|
|
|
/* read_bytes theory: */
|
|
|
|
|
|
|
|
|
|