improve linker script

This commit is contained in:
mykola2312 2024-08-04 19:28:15 +03:00
parent 4afc9680ab
commit 7b1e185790
2 changed files with 39 additions and 31 deletions

View file

@ -1,35 +1,45 @@
MEMORY MEMORY
{ {
BOOTLOADER (RWX) : ORIGIN = 0x0000, LENGTH = 440 RAM (RWX) : ORIGIN = 0x0000, LENGTH = 492032
UNIQUE_ID (R) : ORIGIN = 0x01B8, LENGTH = 4
RESERVED (R) : ORIGIN = 0x01BC, LENGTH = 2
PTABLE (R) : ORIGIN = 0x01BE, LENGTH = 64
MBR_MAGIC (R) : ORIGIN = 0x01FE, LENGTH = 2
} }
SECTIONS SECTIONS
{ {
.text 0x0000 : { RAM = 0x7E00;
RAM_SEGMENT = (RAM >> 8);
.text 0x0000 : {
BOOTLOADER_START = .; BOOTLOADER_START = .;
*(.text) *(.text)
*(.rodata) *(.rodata)
BOOTLOADER_END = .; BOOTLOADER_END = .;
*(.bss)
BOOTLOADER_SIZE = BOOTLOADER_END - BOOTLOADER_START; BOOTLOADER_SIZE = BOOTLOADER_END - BOOTLOADER_START;
} > RAM
RAM = 0x7E00; .stack (NOLOAD): {
RAM_SEGMENT = (RAM >> 8); . = ALIGN(8);
} STACK_SIZE = 0x100;
STACK_START = .;
. = . + STACK_SIZE;
. = ALIGN(8);
STACK_END = .;
} > RAM
.unique_id 0x01B8 : { .bss (NOLOAD) : {
. = ALIGN(8);
*(.bss)
} > RAM
.unique_id 0x01B8 : {
SHORT(0x1234) SHORT(0x1234)
} }
.reserved 0x01BC : { .reserved 0x01BC : {
SHORT(0x0000) SHORT(0x0000)
} }
.mbr_magic 0x01FE : { .mbr_magic 0x01FE : {
SHORT(0xAA55) SHORT(0xAA55)
} }
} }

View file

@ -1,17 +1,20 @@
.section .text .section .text
.code16 .code16
# we're moving to 0050, 0x7C00 -> 0x0500 # initialize stack
# so, DS is 0x07C0 and ES is 0x0050 mov $RAM_SEGMENT, %ax
mov $0x07C0, %ax mov %ax, %ss
mov %ax, %ds mov $STACK_END, %sp
mov $0x0050, %ax
mov %ax, %es # we're moving to 0x7C00 -> 0x7E00
push $0x07C0
pop %ds
push %ss
pop %es
# set both source and destination pointers to zero, since we using segments # set both source and destination pointers to zero, since we using segments
xor %ax, %ax xor %si, %si
mov %ax, %si xor %di, %di
mov %ax, %di
# set counter with determined size by linker # set counter with determined size by linker
mov $BOOTLOADER_SIZE, %cx mov $BOOTLOADER_SIZE, %cx
@ -22,16 +25,11 @@
loop .copy loop .copy
# far jump to new memory region # far jump to new memory region
jmp $0x0050,$.bootloader jmp $RAM_SEGMENT,$.bootloader
.bootloader: .bootloader:
# initialize stack # set DS segment
mov $0x07DF, %ax push %es
mov %ax, %ss pop %ds
xor %sp, %sp
# set ES segment
push %ds
pop %es
.entry: .entry:
call serial_init call serial_init