[go: nahoru, domu]

Skip to content

Commit

Permalink
export tss reference from assembly to c code
Browse files Browse the repository at this point in the history
  • Loading branch information
PauloMigAlmeida committed Dec 18, 2021
1 parent 6ff0623 commit 8261691
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
32 changes: 32 additions & 0 deletions include/kernel/arch/tss.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* tss.h
*
* Created on: 18/12/2021
* Author: Paulo Almeida
*/

#ifndef INCLUDE_KERNEL_ARCH_TSS_H_
#define INCLUDE_KERNEL_ARCH_TSS_H_

#include "kernel/compiler/freestanding.h"
#include "kernel/compiler/macro.h"

typedef struct {
uint32_t res0;
uint64_t rsp0;
uint64_t rsp1;
uint64_t rsp2;
uint64_t res1;
uint64_t ist1;
uint64_t ist2;
uint64_t ist3;
uint64_t ist4;
uint64_t ist5;
uint64_t ist6;
uint64_t ist7;
uint64_t res2;
uint16_t res3;
uint16_t iopb;
} __packed tss_t;

#endif /* INCLUDE_KERNEL_ARCH_TSS_H_ */
4 changes: 2 additions & 2 deletions src/kernel/gdt64.asm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ GDT64.Table.Pointer:
dw GDT64.Table.Size - 1 ; Limit = offset of last byte in table
dq GDT64.Table

TSS64.Segment:
TSS64_Segment:
dd 0x00 ; Reserved
dq 0x00 ; RSP0 (Ring 0 64-bit stack canonical address)
dq 0x00 ; RSP1 (Ring 1 64-bit stack canonical address)
Expand All @@ -95,6 +95,6 @@ TSS64.Segment:
dw 0x00 ; Reserved
dw 0x00 ; I/O Map Base Address

TSS64.Segment.Size equ ($ - TSS64.Segment)
TSS64.Segment.Size equ ($ - TSS64_Segment)

%endif ; __ALMEIDAOS_GDT64_INC__
15 changes: 8 additions & 7 deletions src/kernel/start.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

section .data

; Include useful functions, constants and macros
%include "../../include/boot/global/const.asm"
%include "../../include/boot/global/mem.asm"
%include "./gdt64.asm"

; Export references to C
global e820_mem_start
global e820_mem_end
global TSS64_Segment

; Include useful functions, constants and macros
%include "../../include/boot/global/const.asm"
%include "../../include/boot/global/mem.asm"
%include "./gdt64.asm"

; variables
e820_mem_start: dq e820.Mem.Start.Address
Expand Down Expand Up @@ -37,7 +38,7 @@ kernel_entry:
lgdt [rdi]

; Prepare TSS Segment
mov rdi, TSS64.Segment
mov rdi, TSS64_Segment
; RSP0 (lower 32 bits)
mov DWORD[rdi+4], Kernel.New.Start.VirtualAddress & 0xffffffff
; RSP0 (upper 32 bits)
Expand All @@ -46,7 +47,7 @@ kernel_entry:

; Prepare TSS Descriptor
mov rdi, TSS64.Descriptor
mov rsi, TSS64.Segment
mov rsi, TSS64_Segment
; Set Base Low [15:00]
mov [rdi+2], si
shr rsi, 16
Expand Down

0 comments on commit 8261691

Please sign in to comment.