logo
down
shadow

Jump from bootloader generates exception


Jump from bootloader generates exception

Content Index :

Jump from bootloader generates exception
Tag : c , By : Mena
Date : November 28 2020, 08:01 AM


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to jump into bootloader in Ada?


Tag : development , By : Henry Fatino
Date : March 29 2020, 07:55 AM
Hope this helps I did a small experiment on this Macbook Pro, and your code seems to do what you meant it to; I modified the code to read
with System;

procedure Bootloader is

   procedure Call;
   pragma No_Return (Call);
   pragma Import (Assembler, Call);
   for Call'Address use System'To_Address (16#0E00#);

begin
   Call;
end Bootloader;
        .text
        .globl __ada_bootloader
__ada_bootloader:
LFB1:
        pushq   %rbp
LCFI0:
        movq    %rsp, %rbp
LCFI1:
        subq    $16, %rsp
LCFI2:
        movq    $3584, -8(%rbp)
        movq    -8(%rbp), %rax
        call    *%rax
        leave
LCFI3:
        ret
[...]
(gdb) run
Starting program: /Users/simon/tmp/bootloader 
Reading symbols for shared libraries ++........................ done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000e00
0x0000000000000e00 in ?? ()
(gdb) bt
#0  0x0000000000000e00 in ?? ()
Cannot access memory at address 0xe00
#1  0x0000000100000d93 in main (argc=1, argv=140734799805048, envp=140734799805064) at /Users/simon/tmp/b~bootloader.adb:121
#2  0x0000000100000bf4 in start ()

Far jump in gdt in bootloader


Tag : assembly , By : user143729
Date : March 29 2020, 07:55 AM
Hope this helps x86 supports two virtual memory schemes (read about it here):
segmentation, must, managed using the segment table, GDT. paging, optional, managed using the page table, PDT.
0000000000001     0         00
index 1 (code)   GDT    privileged
0000000000010     0         00
index 2 (data)   GDT    privileged
0000000000011     0         11
index 3 (code)   GDT   non-privileged
0000000000100     0         11
index 4 (data)   GDT   non-privileged

Near call/jump tables don't always work in a bootloader


Tag : assembly , By : Kaputnik
Date : March 29 2020, 07:55 AM
Does that help The Problem
The answer to your question is buried in your question, it just isn't obvious. You quoted my General Bootloader Tips:
call print_char
jmp somewhereelse
call [call_tbl]       ; Call print_char using near indirect absolute call
                      ; via memory operand
call [ds:call_tbl]    ; Call print_char using near indirect absolute call
                      ; via memory operand w/segment override
call near [si]        ; Call print_char using near indirect absolute call
                      ; via register
objdump -mi8086 -Mintel -D -b binary boot.bin --adjust-vma 0x7c00
boot.bin:     file format binary

Disassembly of section .data:

00007c00 <.data>:
    7c00:   31 c0                   xor    ax,ax
    7c02:   8e d8                   mov    ds,ax
    7c04:   fa                      cli
    7c05:   8e d0                   mov    ss,ax
    7c07:   bc 00 7c                mov    sp,0x7c00
    7c0a:   fb                      sti
    7c0b:   be 34 7c                mov    si,0x7c34
    7c0e:   a0 36 7c                mov    al,ds:0x7c36
    7c11:   e8 18 00                call   0x7c2c              ; Relative call works
    7c14:   a0 37 7c                mov    al,ds:0x7c37
    7c17:   ff 16 34 7c             call   WORD PTR ds:0x7c34  ; Near/Indirect/Absolute call
    7c1b:   3e ff 16 34 7c          call   WORD PTR ds:0x7c34  ; Near/Indirect/Absolute call
    7c20:   ff 14                   call   WORD PTR [si]       ; Near/Indirect/Absolute call
    7c22:   a0 38 7c                mov    al,ds:0x7c38
    7c25:   e8 04 00                call   0x7c2c              ; Relative call works
    7c28:   fa                      cli
    7c29:   f4                      hlt
    7c2a:   eb fd                   jmp    0x7c29
    7c2c:   b4 0e                   mov    ah,0xe              ; Beginning of print_char
    7c2e:   bb 00 00                mov    bx,0x0              ; function
    7c31:   cd 10                   int    0x10
    7c33:   c3                      ret
    7c34:   2c 7c                   sub    al,0x7c             ; 0x7c2c offset of print_char
                                                               ; Only entry in call_tbl
    7c36:   42                      inc    dx                  ; 0x42 = ASCII 'B'
    7c37:   4d                      dec    bp                  ; 0x4D = ASCII 'M'
    7c38:   45                      inc    bp                  ; 0x45 = ASCII 'E'
    ...
    7dfd:   00 55 aa                add    BYTE PTR [di-0x56],dl
call [call_tbl] 
jmp 0x0000:$+5
    jmp 0x0000:farjmp
farjmp:
jmp 0x07c0:$+5

Bootloader for Cortex M4 - Jump to loaded Application


Tag : development , By : Rik
Date : March 29 2020, 07:55 AM
it should still fix some issue I have solved the problem now. I still use the code I posted in my question. The problem was that the .bin-file i write on my processor's flash at 0x420000 was compiled in a way that it thought it is at flash start address (0x400000). When it has loaded the reset vector's address it was at 0x400xyz instead of 0x420xyz so the application jumped to the wrong address.
The solution was to Change the Flash start address to 0x420000 in the project I want to upload via bootloader.

assembly bootloader won't jump to kernel


Tag : assembly , By : kakashi_
Date : March 29 2020, 07:55 AM
this one helps. For high level languages there's lots of clues about what the programmer intended contained in the structure loops, how variable names were chosen, defines/enums, etc; and it's easy to write maintainable code without comments.
For assembly language there's no well chosen variable names and no variable types (e.g. ax doesn't tell the reader if it's a pointer to a string or a giraffe's height or ...), instructions often don't show the intent (e.g. lea might be used to multiply by a constant and might not be used to load an effective address), control flow is far more flexible (e.g. something like a do(condition1) { } while(condition2) is perfectly fine) and goto (both jmp and conditional branches like jc) are used a lot.
;Memory Layout
;
; 0x009C:0x1000 = 0x000019C0 = stack top
; 0x07C0:0x0000 = 0x00007C00 = load address
; 0x0000:0x7E00 = 0x00007E00 = kernel address

%define STACK_SEGMENT      0x009C
%define STACK_TOP_OFFSET   0x1000
%define LOAD_SEGMENT       0x07C0
%define KERNEL_SEGMENT     0x0000
%define KERNEL_OFFSET      0x7E00

;_______________________________________________

;Entry point
;
;Input
; dl = BIOS boot device number

    mov ax, STACK_SEGMENT
    mov ss, ax
    mov sp, STACK_TOP_OFFSET
    mov ax, LOAD_SEGMENT
    mov ds, ax
    mov es, ax

;Reset disk system
;
;Note: This should be completely unnecessary. We know the BIOS
;      disk services are working correctly and don't need
;      to be reset because the BIOS just used it successfully
;      to load this code into memory.

    xor ah, ah            ;ah = BIOS "reset disk system" function number
    int 13h               ;Call BIOS disk services
    clc                   ;Unnecessary

;Display welcome message

    mov si, msg2
    call print

;Load kernel from disk
; dl = BIOS boot device number

    mov ah, 02h           ;ah = BIOS "read sectors" function number
    xor ax, ax            ;ax = KERNEL_SEGMENT
    mov es, ax
    mov bx, KERNEL_OFFSET ;es:bx = address to load kernel
    mov al, 1h            ;al = number of sectors to read
    mov ch, 0             ;ch = cylinder number for first sector
    mov cl, 2h            ;cl = sector number for first sector
    mov dh, 0             ;dh = head number for first sector
    int 13h               ;Call BIOS disk services

    jc error              ;Handle error if there was one

;Pass control to "kernel"

    jmp KERNEL_SEGMENT:KERNEL_OFFSET
                          ;ah = BIOS "read sectors" function number
                          ;ax = KERNEL_SEGMENT
Related Posts Related QUESTIONS :
  • does the following program cause memory leak?
  • Innacurate file readings from fopen and/or fscanf
  • Searching an element in an Array using Recursive Function in C Language
  • Most fastest C code to count recursively directories in Linux ( without files )
  • Why does C not offer syntactically transparent references like C++ and Java do?
  • Code doesn't get excuted after using continue in while loop
  • How can I maintain correlation between structure definitions and their construction / destruction code?
  • Avoid race conditions when using pointers and threads
  • Binary and Decimal converting
  • How to create input tensors and use with interpreter in Tensorflow Lite (experimental C API)?
  • Unexpected typecasting between values in C
  • Trouble with Forking Process and Calling bc using execve
  • Glib Threads vs GMain Loop Eventing
  • Why does the byte sequence turn when I cast a char array to an integer array?
  • Is there any difference usage in external interrupt between GPIO (AHB bus)and those (APB bus)?
  • Trouble programming AVR to interpret input from Arduino rotary encoder module
  • Is it correct to use a do-while loop inside a for loop? Why and why not?
  • Why we can't use dot for new created pointers to structs
  • Atomicity of fprintf from MPI processes
  • Printing of negative value in c via printf
  • What's the difference between global or local variables regarding the main function?
  • movsd from memory to xmm0 in c x86-64 jit
  • Problem with a function that insert the content of a csv into an array of struct
  • Segmentation Fault running time on sem_post(flag)
  • Extracting values from an incoming bluetooth serial on an arduino
  • "How much memory space does an array takes if the maximum size that is declared is not used?"
  • C GTK2 frustrated with gnome documentation
  • What really happens when a dynamic memory allocation is explicitly converted to struct type?
  • Re-Indexing Bits Within a Char
  • pointer de-referencing balagurusamy
  • Is it safe to memcpy regex_t?
  • Find a tight upper bound on complexity of the below program:
  • FFTW results differ from FFT in MATLAB
  • How to fix Misra 2012 violation , " Assignment operation in expression "
  • What is the difference between "int *p =0;" and "int *p; *p=0;"
  • Strncpy gives unwanted characters at end of string
  • What is really happening behind when a constant is assigned to a pointer variable?
  • Having trouble tracking logic of program includes Fork()
  • Are leftshift operators dependent on register size?
  • How to pass and receive back pointer to array of structures?
  • How to convert 2 bytes into a signed short in C
  • Using while loop to print Ascii Table with 10 characters per line
  • Is it possible to compress binary files with Huffman-encoding?
  • Why I am getting missing terminating " character?
  • Function call problem in data structure learning
  • Getting a segmentation fault trying to pass a node
  • Copying chars from file into an array
  • How to measure the time in seconds between two characters while user inserting them as an input
  • How to print two strings on the same line in c
  • Passing ("text"+1) argument to Strlen function in C. Why is Output 3?
  • to find the total no of letter in a string. please checkout my code too
  • Why do hiredis functions use void* instead of redisReply*?
  • Is there any case where the C static keyword should or could be used in header files for variables?
  • Sort an array in the relative order of elements of another array in c
  • Why functional programming over c
  • Re-assign value to variable if rand() repeats a number
  • does decrementing a NULL pointer lead to undefined behavior?
  • Access global variable value in different .c files present in different paths
  • Voltage Measurement on STM32
  • Printf behaviour with $ notation when sequence of arguments incomplete
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com