Compare commits

...

2 Commits

Author SHA1 Message Date
ab032e6324
Change to setting up the initial stack in main 2023-03-25 08:39:29 -05:00
c397a4bbf4
Improve bootsector linking 2023-03-25 08:34:42 -05:00
5 changed files with 31 additions and 26 deletions

View File

@ -1,6 +1,5 @@
include_rules
LDFLAGS += -T boot.ld
LDFLAGS += -T boot.ld -z max-page-size=1
: foreach *.68k |> !as |>
: *.o | boot.ld |> !ld |> boot.elf
: boot.elf |> m68k-elf-objcopy -O binary %f %o |> boot.bin
: *.o | boot.ld |> !ld |> boot.bin

View File

@ -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: */

View File

@ -1,5 +1,12 @@
OUTPUT_FORMAT(binary)
MEMORY {
bootsector : ORIGIN = 0, LENGTH = 512
free_ram : ORIGIN = 512, LENGTH = (4096 - 512)
}
SECTIONS {
. = 0x0;
_etext = .;
.text : { *(.text) }
.text : { *(.text) . = 512; } > bootsector
.data : { *(.data) } > bootsector
.bss : { *(.bss) } > free_ram
}

View File

@ -1,6 +1,11 @@
.global main
main:
move.l #inital_stack, a7 | Load the initial stack pointer
move.b #'H', 0xFF0200
move.b #'i', 0xFF0200
move.b #0xA, 0xFF0200
stop #0x2700
.bss
.ds.b 16384
inital_stack:

View File

@ -67,7 +67,6 @@ jmp in_higher:l | Jump to the higher half (THis function has been called with th
in_higher:
move.w #0, 0xff0000 | Disable the IO space at the top of the lower 16MB of memory
move.l #0, (0x0, a0) | Disable the mapping in the lower quarter
move.l #bootstrap_stack, a7 | Load the initial stack pointer
jmp main | Jump to the kernel's main function
@ -76,8 +75,4 @@ jmp main | Jump to the kernel's main function
kernel_map:
.balign 4096
.ds.b 4096
kernel_map_end:
.bss
.ds.b 16384
bootstrap_stack: