improve linker script
This commit is contained in:
parent
4afc9680ab
commit
7b1e185790
2 changed files with 39 additions and 31 deletions
|
|
@ -1,35 +1,45 @@
|
|||
MEMORY
|
||||
{
|
||||
BOOTLOADER (RWX) : ORIGIN = 0x0000, LENGTH = 440
|
||||
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
|
||||
RAM (RWX) : ORIGIN = 0x0000, LENGTH = 492032
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text 0x0000 : {
|
||||
RAM = 0x7E00;
|
||||
RAM_SEGMENT = (RAM >> 8);
|
||||
|
||||
.text 0x0000 : {
|
||||
BOOTLOADER_START = .;
|
||||
*(.text)
|
||||
*(.rodata)
|
||||
BOOTLOADER_END = .;
|
||||
*(.bss)
|
||||
BOOTLOADER_SIZE = BOOTLOADER_END - BOOTLOADER_START;
|
||||
} > RAM
|
||||
|
||||
RAM = 0x7E00;
|
||||
RAM_SEGMENT = (RAM >> 8);
|
||||
}
|
||||
.stack (NOLOAD): {
|
||||
. = ALIGN(8);
|
||||
STACK_SIZE = 0x100;
|
||||
|
||||
.unique_id 0x01B8 : {
|
||||
STACK_START = .;
|
||||
. = . + STACK_SIZE;
|
||||
. = ALIGN(8);
|
||||
STACK_END = .;
|
||||
} > RAM
|
||||
|
||||
.bss (NOLOAD) : {
|
||||
. = ALIGN(8);
|
||||
*(.bss)
|
||||
} > RAM
|
||||
|
||||
.unique_id 0x01B8 : {
|
||||
SHORT(0x1234)
|
||||
}
|
||||
|
||||
.reserved 0x01BC : {
|
||||
.reserved 0x01BC : {
|
||||
SHORT(0x0000)
|
||||
}
|
||||
|
||||
.mbr_magic 0x01FE : {
|
||||
.mbr_magic 0x01FE : {
|
||||
SHORT(0xAA55)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,20 @@
|
|||
.section .text
|
||||
.code16
|
||||
|
||||
# we're moving to 0050, 0x7C00 -> 0x0500
|
||||
# so, DS is 0x07C0 and ES is 0x0050
|
||||
mov $0x07C0, %ax
|
||||
mov %ax, %ds
|
||||
mov $0x0050, %ax
|
||||
mov %ax, %es
|
||||
# initialize stack
|
||||
mov $RAM_SEGMENT, %ax
|
||||
mov %ax, %ss
|
||||
mov $STACK_END, %sp
|
||||
|
||||
# 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
|
||||
xor %ax, %ax
|
||||
mov %ax, %si
|
||||
mov %ax, %di
|
||||
xor %si, %si
|
||||
xor %di, %di
|
||||
|
||||
# set counter with determined size by linker
|
||||
mov $BOOTLOADER_SIZE, %cx
|
||||
|
|
@ -22,16 +25,11 @@
|
|||
loop .copy
|
||||
|
||||
# far jump to new memory region
|
||||
jmp $0x0050,$.bootloader
|
||||
jmp $RAM_SEGMENT,$.bootloader
|
||||
.bootloader:
|
||||
# initialize stack
|
||||
mov $0x07DF, %ax
|
||||
mov %ax, %ss
|
||||
xor %sp, %sp
|
||||
|
||||
# set ES segment
|
||||
push %ds
|
||||
pop %es
|
||||
# set DS segment
|
||||
push %es
|
||||
pop %ds
|
||||
|
||||
.entry:
|
||||
call serial_init
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue