2018-01-26 08:43:22 +00:00
|
|
|
#ifndef _HAL_CPU_H_
|
|
|
|
#define _HAL_CPU_H_
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-01-25 09:53:35 +00:00
|
|
|
#include "type.h"
|
2018-01-26 08:43:22 +00:00
|
|
|
#include "kernel/hal/atomic.h"
|
2016-07-09 03:01:33 +00:00
|
|
|
|
|
|
|
#define HAL_CORE_COUNT 1
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-02-14 07:31:50 +00:00
|
|
|
|
2016-06-14 06:33:31 +00:00
|
|
|
typedef struct
|
2016-06-13 04:11:38 +00:00
|
|
|
{
|
|
|
|
uint16_t limit;
|
|
|
|
uint64_t base;
|
2016-08-28 09:14:22 +00:00
|
|
|
} STRUCT_PACKED hal_gdt_ptr_t;
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2016-06-14 06:33:31 +00:00
|
|
|
typedef struct
|
2016-06-13 04:11:38 +00:00
|
|
|
{
|
|
|
|
uint16_t limit;
|
|
|
|
uint64_t base;
|
2016-08-28 09:14:22 +00:00
|
|
|
} STRUCT_PACKED hal_idt_ptr_t;
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2016-06-24 01:48:34 +00:00
|
|
|
|
2018-01-26 08:43:22 +00:00
|
|
|
/**
|
|
|
|
* CPU Instructions
|
|
|
|
*/
|
2017-02-01 03:26:08 +00:00
|
|
|
extern void KABI hal_cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-01-26 08:43:22 +00:00
|
|
|
extern void KABI hal_halt_cpu(void);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2017-03-27 04:11:08 +00:00
|
|
|
extern void KABI hal_enable_interrupt(void);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2017-03-27 04:11:08 +00:00
|
|
|
extern void KABI hal_disable_interrupt(void);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-01-26 08:43:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* IO Port Operations
|
|
|
|
*/
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2017-02-01 03:26:08 +00:00
|
|
|
extern int8_t KABI hal_read_port_8(uint16_t port);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2017-02-01 03:26:08 +00:00
|
|
|
extern int16_t KABI hal_read_port_16(uint16_t port);
|
2016-06-14 06:57:38 +00:00
|
|
|
|
2017-02-01 03:26:08 +00:00
|
|
|
extern int32_t KABI hal_read_port_32(uint16_t port);
|
2016-06-14 06:57:38 +00:00
|
|
|
|
2017-02-01 03:26:08 +00:00
|
|
|
extern void KABI hal_write_port_8(uint16_t port, uint8_t data);
|
2016-06-14 06:57:38 +00:00
|
|
|
|
2017-02-01 03:26:08 +00:00
|
|
|
extern void KABI hal_write_port_16(uint16_t port, uint16_t data);
|
2016-06-14 06:57:38 +00:00
|
|
|
|
2017-02-01 03:26:08 +00:00
|
|
|
extern void KABI hal_write_port_32(uint16_t port, uint32_t data);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-01-26 08:43:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CPU Structure Operations
|
|
|
|
*/
|
|
|
|
|
2017-02-01 03:26:08 +00:00
|
|
|
extern void KABI hal_flush_gdt(hal_gdt_ptr_t *gdt_ptr, uint64_t code_slct, uint64_t data_slct);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2017-03-27 04:11:08 +00:00
|
|
|
extern void KABI hal_flush_tlb(void);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2017-02-01 03:26:08 +00:00
|
|
|
extern void KABI hal_flush_idt(hal_idt_ptr_t *idt_ptr);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2017-02-01 03:26:08 +00:00
|
|
|
extern void KABI hal_read_idt(hal_idt_ptr_t **idt_ptr);
|
2016-06-14 06:33:31 +00:00
|
|
|
|
2018-01-26 08:43:22 +00:00
|
|
|
/**
|
|
|
|
* Control Register Operations
|
|
|
|
*/
|
|
|
|
#define MSR_IA32_APIC_BASE 0x1B
|
|
|
|
extern void KABI hal_read_msr(uint32_t *ecx, uint32_t *edx, uint32_t *eax);
|
|
|
|
|
|
|
|
extern void KABI hal_write_msr(uint32_t *ecx, uint32_t *edx, uint32_t *eax);
|
|
|
|
|
2017-02-01 03:26:08 +00:00
|
|
|
extern void KABI hal_write_cr3(uint64_t base);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2017-03-27 04:11:08 +00:00
|
|
|
extern uint64_t KABI hal_read_cr3(void);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2017-02-01 03:26:08 +00:00
|
|
|
extern void KABI hal_write_cr8(uint64_t pri);
|
2016-06-15 07:29:46 +00:00
|
|
|
|
2017-03-27 04:11:08 +00:00
|
|
|
extern uint64_t KABI hal_read_cr8(void);
|
2016-06-15 07:29:46 +00:00
|
|
|
|
2018-01-26 08:43:22 +00:00
|
|
|
|
|
|
|
|
2016-06-13 04:11:38 +00:00
|
|
|
#endif
|