Improve bootsector linking
This commit is contained in:
parent
d8565dcd78
commit
c397a4bbf4
@ -1,6 +1,5 @@
|
|||||||
include_rules
|
include_rules
|
||||||
LDFLAGS += -T boot.ld
|
LDFLAGS += -T boot.ld -z max-page-size=1
|
||||||
|
|
||||||
: foreach *.68k |> !as |>
|
: foreach *.68k |> !as |>
|
||||||
: *.o | boot.ld |> !ld |> boot.elf
|
: *.o | boot.ld |> !ld |> boot.bin
|
||||||
: boot.elf |> m68k-elf-objcopy -O binary %f %o |> boot.bin
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
.equ SEC_BUF_START, 0x400
|
|
||||||
.equ PHDR_BUF_START, 0x600
|
|
||||||
.equ PHDR_BUF_SEC_SIZE, 5
|
.equ PHDR_BUF_SEC_SIZE, 5
|
||||||
.equ STORAGE_SEC, 0x0
|
.equ STORAGE_SEC, 0x0
|
||||||
.equ STORAGE_CNT, 0x4
|
.equ STORAGE_CNT, 0x4
|
||||||
@ -11,14 +9,14 @@ _start:
|
|||||||
move.w #0x4, d0 | Find a storage card
|
move.w #0x4, d0 | Find a storage card
|
||||||
bsr.w find_first_card
|
bsr.w find_first_card
|
||||||
| load the first PHDR_BUF_SEC_SIZE sectors of the ELF kernel binary off the disk
|
| 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 #0x2, d0 | Set the starting sector number to 2
|
||||||
move.l #PHDR_BUF_SEC_SIZE, d1 | Set the sector count
|
move.l #PHDR_BUF_SEC_SIZE, d1 | Set the sector count
|
||||||
bsr.w read_sectors
|
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 + 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, a1 | Put the address of the program headers in a1
|
||||||
adda.w d0, 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
|
subq.w #0x1, d0
|
||||||
phead_loop:
|
phead_loop:
|
||||||
move.l (a1), d1 | If the type of the program header isn't 1 (LOAD), skip the header
|
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:
|
next_seg:
|
||||||
lea (0x20, a1), a1 | Advance a1 to point to the next program header
|
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
|
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 + 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 + 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, a0 | Put the address of the program headers in a0
|
||||||
adda.w d0, 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
|
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
|
lsr.l #1, d0
|
||||||
move.l d0, d5 | Save the starting sector in d5
|
move.l d0, d5 | Save the starting sector in d5
|
||||||
move.l #1, d1 | Read the starting sector into the sector buffer
|
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
|
bsr.b read_sectors
|
||||||
move.l a6, a2 | Load the destination into a2
|
move.l a6, a2 | Load the destination into a2
|
||||||
move.l d6, d0 | Load the start byte into d0
|
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
|
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
|
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 #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
|
bsr.b read_sectors | Read the end sector
|
||||||
move.l d6, d1 | Load the number of remaining bytes into d1
|
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
|
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:
|
read_bytes_done:
|
||||||
rts
|
rts
|
||||||
|
|
||||||
.if . != 512
|
.section .bss
|
||||||
.org 511
|
sec_buf:
|
||||||
.byte 0
|
.ds.b 512
|
||||||
.endif
|
phdr_buf:
|
||||||
|
.ds.b (PHDR_BUF_SEC_SIZE * 512)
|
||||||
|
|
||||||
/* read_bytes theory: */
|
/* read_bytes theory: */
|
||||||
|
|
||||||
|
11
boot/boot.ld
11
boot/boot.ld
@ -1,5 +1,12 @@
|
|||||||
|
OUTPUT_FORMAT(binary)
|
||||||
|
|
||||||
|
MEMORY {
|
||||||
|
bootsector : ORIGIN = 0, LENGTH = 512
|
||||||
|
free_ram : ORIGIN = 512, LENGTH = (4096 - 512)
|
||||||
|
}
|
||||||
SECTIONS {
|
SECTIONS {
|
||||||
. = 0x0;
|
. = 0x0;
|
||||||
_etext = .;
|
.text : { *(.text) . = 512; } > bootsector
|
||||||
.text : { *(.text) }
|
.data : { *(.data) } > bootsector
|
||||||
|
.bss : { *(.bss) } > free_ram
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user